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