Script to Export Office 365 Group Information to CSV
This script retrieves all Office 365 groups in the tenant, including details such as group name, alias, type, owners, members, privacy settings, and associated SharePoint site URLs. It also captures metadata like the group’s creation and last modified time. The script then exports this information into a CSV file, making it easier to audit and review Office 365 groups, their owners, and membership details across the organization. The CSV file is saved to a specified path for further analysis or reporting.
Here is the script:
Specify CSV file path
Section titled “Specify CSV file path”$csvFilePath = “Office365GroupsInfo.csv”
Get all Office 365 groups
Section titled “Get all Office 365 groups”$groups = Get-UnifiedGroup -ResultSize Unlimited
Prepare CSV data
Section titled “Prepare CSV data”$csvData = foreach ($group in $groups) { [PSCustomObject]@{ ‘Group Name’ = $group.DisplayName ‘Group Alias’ = $group.Alias ‘Group Type’ = $group.GroupType ‘Owners’ = (Get-UnifiedGroupLinks -Identity $group.DistinguishedName -LinkType Owners | Select-Object -ExpandProperty PrimarySmtpAddress | ForEach-Object {$}) -join ’,’ ‘Members’ = (Get-UnifiedGroupLinks -Identity $group.DistinguishedName -LinkType Members | Select-Object -ExpandProperty PrimarySmtpAddress | ForEach-Object {$}) -join ’,’ ‘Privacy’ = $group.AccessType ‘Managed By’ = $group.ManagedBy ‘Description’ = $group.Description ‘Creation Time’ = $group.WhenCreated ‘Last Modified Time’ = $group.WhenChanged ‘Site URL’ = $group.SharePointSiteUrl } }
Export to CSV
Section titled “Export to CSV”$csvData | Export-Csv -Path $csvFilePath -NoTypeInformation -Force