Script to Export Office 365 Group Information to CSV

2 min. readlast update: 09.26.2024

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
$csvFilePath = "Office365GroupsInfo.csv"
 
# Get all Office 365 groups
$groups = Get-UnifiedGroup -ResultSize Unlimited
 
# 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
$csvData | Export-Csv -Path $csvFilePath -NoTypeInformation -Force
Was this article helpful?