Skip to content

Instantly share code, notes, and snippets.

  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
#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 = ""
#connect to your SharePoint admin site.
$connection = connect-pnponline -managedidentity -url "" -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"
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