Entra / Microsoft 365 · Compliance & audit
Check sensitivity labels on groups
Originally featured in https://practical365.com/monitor-changes-sensitivity-labels-container-management/.
Connect & set up
Run these once per session. All scopes are read-only unless the script makes changes.
Connect-ExchangeOnline -SkipLoadingCmdletHelp
Run it
The main script. Copy it, or download the .ps1 and run it from your console.
$Status = Get-ConnectionInformation -ErrorAction SilentlyContinueIf (!($Status)) {Connect-ExchangeOnline -SkipLoadingCmdletHelp}Connect-IPPSSession# Define the default sensitivity label$DefaultSensitivityLabel = "e42fd42e-7240-4df0-9d8f-d14658bcf7ce" # Guid for General Access# Create a list of the sensitivity labels used for container management in the organization[array]$Labels = Get-Label$ContainerLabels = [System.Collections.Generic.List[Object]]::new()ForEach ($Label in $Labels) {If ($Label.ContentType -Like "*UnifiedGroup*") { # It's a label for container management$DataLine = [PSCustomObject] @{LabelId = $Label.ImmutableIdDisplayName = $Label.DisplayNamePriority = $Label.Priority }$ContainerLabels.Add($DataLine)}}# Validate that the default sensitivity label is OKIf ($DefaultSensitivityLabel -notin $ContainerLabels.LabelId) {Write-Host ("Default label {0} is not valid -exiting" -f $DefaultSensitivityLabel)}[int]$LabelsAssigned = 0Write-Host "Fetching Microsoft 365 Groups"[array]$Groups = Get-UnifiedGroup -ResultSize UnlimitedForEach ($Group in $Groups) {If ($null -eq $Group.SensitivityLabel) { # No label assigned so let's assign the default labelWrite-Host ("{0} has no sensitivity label - assigning the default label" -f $Group.DisplayName) -Foregroundcolor RedSet-UnifiedGroup -Identity $Group.ExternalDirectoryObjectId -SensitivityLabel $DefaultSensitivityLabel -CustomAttribute14 $DefaultSensitivityLabel$LabelsAssigned++} Else { # Just update the Custom AttributeSet-UnifiedGroup -Identity $Group.ExternalDirectoryObjectId -CustomAttribute14 $Group.SensitivityLabel}} # End ForWrite-Host ("Labels assigned to {0} Microsoft 365 Groups; checked label tracking attribute for {1} groups" -f $LabelsAssigned, $Groups.Count)
Attribution
Author
Office365itpros