Forum Discussion
Apply default compliance label to document library from code (SPO)
I have exported a Modern Communications site as a template using Get-PnPProvisioningTemplate.
The template has a document library that has a default classification label (defined in the security and compliance centre).
When I create a new site based on the template using PowerShell the document library in new site doesn't have the default classification label applied.
Is there a SharePoint PowerShell or PNP cmdlet that will allow me to define the default classification label for the document library?
I don't think there is a way (yet) to set this property at the library-level. I've checked to see what happens exactly when you set the property using the browser interface. I've noticed differences in the List's Schema XML before and after changing the configuration through the browser. Unfortunately you cannot change the List's Schema XML programmatically and there are no Properties on List that let you change the settings.
However, you can set the Compliance Label programmatically at the item-level:
https://msdn.microsoft.com/en-us/library/microsoft.sharepoint.client.listitem.setcompliancetag.aspx
So (for the time being) you could write a Web Hook or other kind of scheduled / triggered mechanism that uses this API to ensure your documents are properly labeled. You could even call this API from PowerShell if you'd whish.
Hope this helps
- paulpaschaBronze Contributor
I don't think there is a way (yet) to set this property at the library-level. I've checked to see what happens exactly when you set the property using the browser interface. I've noticed differences in the List's Schema XML before and after changing the configuration through the browser. Unfortunately you cannot change the List's Schema XML programmatically and there are no Properties on List that let you change the settings.
However, you can set the Compliance Label programmatically at the item-level:
https://msdn.microsoft.com/en-us/library/microsoft.sharepoint.client.listitem.setcompliancetag.aspx
So (for the time being) you could write a Web Hook or other kind of scheduled / triggered mechanism that uses this API to ensure your documents are properly labeled. You could even call this API from PowerShell if you'd whish.
Hope this helps