Created
March 14, 2023 21:30
-
-
Save AlexanderHolmeset/4f5b98e8d26a45331f8c74fb96305ad0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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