Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlexanderHolmeset/4f5b98e8d26a45331f8c74fb96305ad0 to your computer and use it in GitHub Desktop.
Save AlexanderHolmeset/4f5b98e8d26a45331f8c74fb96305ad0 to your computer and use it in GitHub Desktop.
#set your sensitivity label.
$sensitivitylabel = "18fd20ce-627f-4b00-84ab-b768550d6446"
#set the url of the site/group you want to monitor and set assign label to.
$url = "https://m365x28850929.sharepoint.com/sites/testnogroup"
#connect to your SharePoint admin site.
$connection = connect-pnponline -managedidentity -url "https://m365x28850929-admin.sharepoint.com/" -returnconnection
$site = get-pnptenantsite -url $url -connection $connection
write-output "SP-Site: $($site.sensitivitylabel)"
connect-pnponline -managedidentity -url $url
$OriginalLabel = (get-pnppropertybag | where-object{$_.key -like "OriginalLabel"}).value
write-output "OriginalLabel: $OriginalLabel"
if(!$OriginalLabel){
write-output "Creating OriginalLabel property."
#we are temporary allowing scripts to be run on the SharePoint site.
set-pnpsite -url $url -NoScriptSite $false -connection $connection
Add-PnPPropertyBagValue -Key OriginalLabel -Value $SensitivityLabel
set-pnpsite -url $url -NoScriptSite $true -connection $connection
}
If($Site.SensitivityLabel -notlike $OriginalLabel -or !$Site.SensitivityLabel ){
write-output "Setting sensitivitylabel on site."
set-pnptenantsite -url $url -sensitivitylabel $sensitivitylabel -connection $connection
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment