Skip to content

Instantly share code, notes, and snippets.

@joerodgers
Last active June 26, 2024 20:58
Show Gist options
  • Save joerodgers/fa4f34e9fde1042658f09ad800d4ebdb to your computer and use it in GitHub Desktop.
Save joerodgers/fa4f34e9fde1042658f09ad800d4ebdb to your computer and use it in GitHub Desktop.
#requires -modules "PnP.PowerShell"
Connect-PnPOnline `
-Url "https://$env:O365_TENANT-admin.sharepoint.com" `
-ClientId $env:O365_CLIENTID `
-Thumbprint $env:O365_THUMBPRINT `
-Tenant $env:O365_TENANTID `
-ErrorAction Stop
$unifiedGroups = Get-PnPMicrosoft365Group
$publicUnifiedGroups = $unifiedGroups | Where-Object -Property Visibility -eq "public"
$results = foreach( $unifiedGroup in $publicUnifiedGroups )
{
# this method avoids a access token expiration issue
$unifiedGroupDetail = Get-PnPMicrosoft365Group -Identity $unifiedGroup.GroupId -IncludeSiteUrl -IncludeOwners
[PSCustomObject] @{
GroupName = $unifiedGroup.DisplayName
GroupId = $unifiedGroup.Id
CreatedDateTime = $unifiedGroup.CreatedDateTime
GroupOwnerEmails = $unifiedGroupDetail.Owners.Email -join ";"
SiteUrl = $unifiedGroupDetail.SiteUrl
IsMicrosoftTeamsConnected = $unifiedGroup.HasTeam
IsVivaEngageConnected = $unifiedGroup.CreationOptions -contains "YammerProvisioning"
}
}
$timestamp = Get-Date -Format FileDateTime
$results | Export-Csv -Path "PublicM365Groups_$timestamp.csv" -NoTypeInformation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment