Last active
June 21, 2024 15:36
-
-
Save joerodgers/abe2eab302f5220461fb7233ec3cf605 to your computer and use it in GitHub Desktop.
Shows all M365 group connected sites and reports if the associated M365 group exists.
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
#requires -module "PnP.PowerShell" | |
# Required permissions: | |
# Microsoft Graph API : One of Directory.Read.All, Directory.ReadWrite.All, Group.Read.All, Group.ReadWrite.All, GroupMember.Read.All, GroupMember.ReadWrite.All | |
# SharePoint Online : Sites.FullControl.All | |
Connect-PnPOnline ` | |
-Url "https://$env:O365_TENANT-admin.sharepoint.com" ` | |
-ClientId $env:O365_CLIENTID ` | |
-Thumbprint $env:O365_THUMBPRINT ` | |
-Tenant $env:O365_TENANTID ` | |
-ErrorAction Stop | |
$sites = Get-PnPTenantSite -GroupIdDefined $true -ErrorAction Stop | |
$results = foreach( $site in $sites ) | |
{ | |
Write-Host "[$(Get-date)] - Scanning site: $($site.Url)" | |
if( $site.GroupId -ne [Guid]::Empty ) | |
{ | |
$groupId = $site.GroupId | |
} | |
else | |
{ | |
$groupId = $site.RelatedGroupId | |
} | |
try | |
{ | |
$group = Get-PnPMicrosoft365Group -Identity $groupId -ErrorAction Stop | |
} | |
catch | |
{ | |
Write-Error "Failed to lookup group: $groupId. Error: $_" | |
} | |
[PSCustomObject] @{ | |
SiteUrl = $site.Url | |
GroupId = $site.GroupId | |
RelatedGroupId = $site.RelatedGroupId | |
GroupExists = $null -ne $group | |
} | |
} | |
$results | Export-Csv -Path "M365GroupConnectionExists.csv" -NoTypeInformation |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment