|
1 | | -# A script to display details of the retention policies applying to SharePoint and OneDrive for Business sites in an Office 365 tenant. |
2 | | -# Uses the Security and Compliance Center PowerShell module |
3 | | - |
4 | | -$Report = @() |
5 | | -$RetentionPolicies = (Get-RetentionCompliancePolicy -ExcludeTeamsPolicy -DistributionDetail | ? {$_.SharePointLocation -ne $Null}) |
6 | | -# Now exclude all the retention policies that publish labels |
7 | | -$Policies = @() |
8 | | -ForEach ($P in $RetentionPolicies) { |
9 | | - $Rule = Get-RetentionComplianceRule -Policy $P.Name |
10 | | - If ([string]::IsNullOrWhiteSpace($Rule.RetentionDuration) -and [string]::IsNullOrWhiteSpace($Rule.ApplyComplianceTag)) { |
11 | | - Write-Host "Policy" $P.Name "publishes retention labels to workloads - excluded from this report" } |
12 | | - Else { |
13 | | - $Policies += $P } |
14 | | -} |
15 | | -# Now we have a cleansed set of retention policies that apply to SharePoint |
16 | | -ForEach ($P in $Policies) { |
17 | | - $Duration = $Null |
18 | | - Write-Host "Processing retention policy" $P.Name |
19 | | - $Rule = Get-RetentionComplianceRule -Policy $P.Name |
20 | | - $Settings = "Simple" |
21 | | - $Duration = $Rule.RetentionDuration |
22 | | - # Check whether a rule is for advanced settings - either a KQL query or sensitive data types |
23 | | - If (-not [string]::IsNullOrWhiteSpace($Rule.ContentMatchQuery) -and -not [string]::IsNullOrWhiteSpace($Rule.ContentMatchQuery)) { |
24 | | - $Settings = "Advanced/KQL" } |
25 | | - Elseif (-not [string]::IsNullOrWhiteSpace($Rule.ContentContainsSensitiveInformation) -and -not [string]::IsNullOrWhiteSpace($Rule.ContentContainsSensitiveInformation)) { |
26 | | - $Settings = "Advanced/Sensitive Data" } |
27 | | - # Handle retention policy using advanced settings (keyword search or sensitive data type) |
28 | | - If ($Rule.RetentionDuration -eq $Null -and $Rule.ApplyComplianceTag -ne $Null) { |
29 | | - $Duration = (Get-ComplianceTag -Identity $Rule.ApplyComplianceTag | Select -Expandproperty RetentionDuration) } |
30 | | - $RetentionAction = $Rule.RetentionComplianceAction |
31 | | - If ([string]::IsNullOrEmpty($RetentionAction)) { |
32 | | - $RetentionAction = "Retain" } |
33 | | - If ($P.SharePointLocation.Name -eq "All") { |
34 | | - $ReportLine = [PSCustomObject][Ordered]@{ |
35 | | - PolicyName = $P.Name |
36 | | - SiteName = "All SharePoint Sites" |
37 | | - SiteURL = "All SharePoint Sites" |
38 | | - RetentionTime = $Rule.RetentionDurationDisplayHint |
39 | | - RetentionDuration = $Duration |
40 | | - RetentionAction = $RetentionAction |
41 | | - Settings = $Settings} |
42 | | - $Report += $ReportLine } |
43 | | - If ($P.SharePointLocationException -ne $Null) { |
44 | | - $Locations = ($P | Select -ExpandProperty SharePointLocationException) |
45 | | - ForEach ($L in $Locations) { |
46 | | - $Exception = "*Exclude* " + $L.DisplayName |
47 | | - $ReportLine = [PSCustomObject][Ordered]@{ |
48 | | - PolicyName = $P.Name |
49 | | - SiteName = $Exception |
50 | | - SiteURL = $L.Name } |
51 | | - $Report += $ReportLine } |
52 | | - } |
53 | | - ElseIf ($P.SharePointLocation.Name -ne "All") { |
54 | | - $Locations = ($P | Select -ExpandProperty SharePointLocation) |
55 | | - ForEach ($L in $Locations) { |
56 | | - $ReportLine = [PSCustomObject][Ordered]@{ |
57 | | - PolicyName = $P.Name |
58 | | - SiteName = $L.DisplayName |
59 | | - SiteURL = $L.Name |
60 | | - RetentionTime = $Rule.RetentionDurationDisplayHint |
61 | | - RetentionDuration = $Duration |
62 | | - RetentionAction = $RetentionAction |
63 | | - Settings = $Settings} |
64 | | - $Report += $ReportLine } |
65 | | - } |
66 | | -} |
67 | | -$Report | Sort SiteName| Format-Table PolicyName, SiteName, RetentionDuration, RetentionAction, Settings -AutoSize |
68 | | - |
| 1 | +# A script to display details of the retention policies applying to SharePoint and OneDrive for Business sites in an Office 365 tenant. |
| 2 | +# Uses the Security and Compliance Center PowerShell module |
| 3 | + |
| 4 | +$Report = @() |
| 5 | +# Fetch a set of retention policies that apply to SharePoint and aren't to publish labels |
| 6 | +$Policies = (Get-RetentionCompliancePolicy -ExcludeTeamsPolicy -DistributionDetail -RetentionRuleTypes | ? {$_.SharePointLocation -ne $Null -and $_.RetentionRuleTypes -ne "Publish"}) |
| 7 | +ForEach ($P in $Policies) { |
| 8 | + $Duration = $Null |
| 9 | + Write-Host "Processing retention policy" $P.Name |
| 10 | + $Rule = Get-RetentionComplianceRule -Policy $P.Name |
| 11 | + $Settings = "Simple" |
| 12 | + $Duration = $Rule.RetentionDuration |
| 13 | + # Check whether a rule is for advanced settings - either a KQL query or sensitive data types |
| 14 | + If (-not [string]::IsNullOrWhiteSpace($Rule.ContentMatchQuery) -and -not [string]::IsNullOrWhiteSpace($Rule.ContentMatchQuery)) { |
| 15 | + $Settings = "Advanced/KQL" } |
| 16 | + Elseif (-not [string]::IsNullOrWhiteSpace($Rule.ContentContainsSensitiveInformation) -and -not [string]::IsNullOrWhiteSpace($Rule.ContentContainsSensitiveInformation)) { |
| 17 | + $Settings = "Advanced/Sensitive Data" } |
| 18 | + # Handle retention policy that simply retains and doesn't do anything else |
| 19 | + If ($Rule.RetentionDuration -eq $Null -and $Rule.ApplyComplianceTag -ne $Null) { |
| 20 | + $Duration = (Get-ComplianceTag -Identity $Rule.ApplyComplianceTag | Select -Expandproperty RetentionDuration) } |
| 21 | + $RetentionAction = $Rule.RetentionComplianceAction |
| 22 | + If ([string]::IsNullOrEmpty($RetentionAction)) { |
| 23 | + $RetentionAction = "Retain" } |
| 24 | + If ($P.SharePointLocation.Name -eq "All") { |
| 25 | + $ReportLine = [PSCustomObject][Ordered]@{ |
| 26 | + PolicyName = $P.Name |
| 27 | + SiteName = "All SharePoint Sites" |
| 28 | + SiteURL = "All SharePoint Sites" |
| 29 | + RetentionTime = $Rule.RetentionDurationDisplayHint |
| 30 | + RetentionDuration = $Duration |
| 31 | + RetentionAction = $RetentionAction |
| 32 | + Settings = $Settings} |
| 33 | + $Report += $ReportLine } |
| 34 | + If ($P.SharePointLocationException -ne $Null) { |
| 35 | + $Locations = ($P | Select -ExpandProperty SharePointLocationException) |
| 36 | + ForEach ($L in $Locations) { |
| 37 | + $Exception = "*Exclude* " + $L.DisplayName |
| 38 | + $ReportLine = [PSCustomObject][Ordered]@{ |
| 39 | + PolicyName = $P.Name |
| 40 | + SiteName = $Exception |
| 41 | + SiteURL = $L.Name } |
| 42 | + $Report += $ReportLine } |
| 43 | + } |
| 44 | + ElseIf ($P.SharePointLocation.Name -ne "All") { |
| 45 | + $Locations = ($P | Select -ExpandProperty SharePointLocation) |
| 46 | + ForEach ($L in $Locations) { |
| 47 | + $ReportLine = [PSCustomObject][Ordered]@{ |
| 48 | + PolicyName = $P.Name |
| 49 | + SiteName = $L.DisplayName |
| 50 | + SiteURL = $L.Name |
| 51 | + RetentionTime = $Rule.RetentionDurationDisplayHint |
| 52 | + RetentionDuration = $Duration |
| 53 | + RetentionAction = $RetentionAction |
| 54 | + Settings = $Settings} |
| 55 | + $Report += $ReportLine } |
| 56 | + } |
| 57 | +} |
| 58 | +$Report | Sort SiteName| Format-Table PolicyName, SiteName, RetentionDuration, RetentionAction, Settings -AutoSize |
| 59 | + |
0 commit comments