Skip to content

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:  

$csvFilePath = “Office365GroupsInfo.csv”  

$groups = Get-UnifiedGroup -ResultSize Unlimited  

$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     } }  

$csvData | Export-Csv -Path $csvFilePath -NoTypeInformation -Force