How to Find All Office 365 Groups using PowerShell?

Requirement: Get Office 365 Groups using PowerShell.

How to Get Office 365 Groups in Admin Center?

Microsoft Office 365 Groups provide a simple and efficient way to collaborate with other people in your organization. However, manually locating all the groups in your tenant can be a tedious task. This blog post will show you how to use PowerShell to quickly find all Office 365 groups in your tenant.

You can get Office 365 groups through Microsoft 365 admin center as an admin. Follow these steps:

  1. Log in to the Microsoft 365 Admin Center site: https://admin.microsoft.com
  2. Expand “Teams & Groups” and click on “Active teams & groups” in the left navigation. 
  3. On the Groups page, select the “Office 365” tab. That list’s all Office 365 groups on the page.
    get list of office 365 groups powershell

Get Office 365 Group Details using PowerShell

Use the Get-UnifiedGroup cmdlet to get all Office 365 groups in Office 365.

#Get Credentials to connect
$Credential = Get-Credential
 
#Connect to Exchange Online
Connect-ExchangeOnline -Credential $Credential -ShowBanner:$False

#Get all Office 365 Group
Get-UnifiedGroup

#Disconnect Exchange Online
Disconnect-ExchangeOnline -Confirm:$False

This cmdlet retrieves all Office 365 groups.

get office 365 group using powershell

You may query specific properties of the Office 365 group by,

Get-UnifiedGroup | Format-Table Alias, WhenCreated, WhenChanged, SharePointSiteUrl

Similarly, to get an Office 365 group ID using PowerShell, use:

Get-UnifiedGroup -Identity "Marketing" | Select ID

Export Office 365 Groups using PowerShell

Get-UnifiedGroup | Select Guid,DisplayName,Alias, AccessType,ManagedBy,WhenCreated | Export-Csv -Path "C:\Temp\Groups.csv" -NoTypeInformation

This PowerShell generates a CSV file as:

Export Office 365 groups to CSV using powershell

PnP PowerShell to Get All Microsoft 365 Groups

The below PnP PowerShell script gets all Microsoft 365 groups in your tenant and exports groups data to a CSV file:

  • Group Name
  • Group ID
  • Has Microsoft Team
  • Visibility (Private or Public)
  • Group Mail
  • Created Date & Time
  • Group Owners
  • Group Members
#Config Variables
$AdminSiteURL = "https://crescent-admin.sharepoint.com"
$CSVPath = "C:\Temp\GroupsData.csv"

Try {
    #Connect to PnP Online
    Connect-PnPOnline -Url $AdminSiteURL -Interactive

    #Get all Office 365 Groups
    $Groups = Get-PnPMicrosoft365Group
    
    $GroupsData = @()
    #Loop through each group
    ForEach($Group in $Groups)
    {
        Write-host "Processing Group:"$Group.DisplayName
        #Get Owners & Members of the group
        $GroupOwners = (Get-PnPMicrosoft365GroupOwners -Identity $Group | Select -ExpandProperty UserPrincipalName) -join ";"
        $GroupMembers = (Get-PnPMicrosoft365GroupMembers -Identity $Group  | Select -ExpandProperty UserPrincipalName) -join ";"

        #Get Group details
        $GroupsData += New-Object PSObject -property $([ordered]@{ 
            GroupName  = $Group.DisplayName
            Id = $Group.ID
            HasTeam = $Group.HasTeam
            Visibility = $Group.Visibility
            Mail = $Group.Mail
            CreatedDateTime = $Group.CreatedDateTime
            GroupOwners= $GroupOwners
            GroupMembers= $GroupMembers
        })
    }
    $GroupsData
    #Export Groups information to CSV
    $GroupsData | Export-Csv -Path $CSVPath -NoTypeInformation
}
Catch {
    write-host -f Red "Error:" $_.Exception.Message
}

PowerShell to get all Office 365 Groups from Azure AD

We can also get a list of Office 365 groups using Azure AD PowerShell cmdlets.

#Connect to Azure AD
Connect-AzureAD

#Get All Microsoft 365 groups
Get-AzureADMSGroup -Filter "groupTypes/any(c:c eq 'Unified')" -All:$true

To get all owners of Office 365 groups, use: Find All Office 365 Group Owners using PowerShell

Salaudeen Rajack

Salaudeen Rajack - SharePoint Expert with Two decades of SharePoint Experience. Love to Share my knowledge and experience with the SharePoint community, through real-time articles!

Leave a Reply

Your email address will not be published. Required fields are marked *