How to Get All Office 365 Groups using PowerShell?

Requirement: Get Office 365 Groups using PowerShell.

How to Get Office 365 Groups in the Admin Center?

Microsoft Office 365 Groups provide a simple and efficient way to collaborate with others 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.

The Microsoft 365 admin center provides a user-friendly interface for managing your Office 365 environment. You can get Office 365 groups through the Microsoft 365 admin center as an admin. Follow these steps:

  1. Log in to the Microsoft 365 Admin Center site:
  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 lists all Microsoft 365 groups on the page.
    get list of office 365 groups powershell

You can export these groups to Excel using the “Export” button in the command bar.

Get Microsoft 365 Group Details using PowerShell

To get a list of all Office 365 groups in your organization, you can use PowerShell. Use the Get-UnifiedGroup cmdlet to get all Office 365 groups in Office 365. I’m assuming you have the Exchange Online PowerShell module installed already! If not, do it before running these PowerShell scripts. Otherwise, You’ll get “Get-UnifiedGroup : The term ‘Get-UnifiedGroup’ is not recognized as the name of a cmdlet, function, script file, or operable program.” error.

#Connect to Exchange Online
Connect-ExchangeOnline -ShowBanner:$False

#Get all Office 365 Group

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

This cmdlet retrieves all Office 365 groups.

get office 365 group using powershell

The Get-UnifiedGroup Exchange cmdlet syntax goes like this:

   [[-Identity] <UnifiedGroupId>]
   [-Filter <String>]
   [-ResultSize <Unlimited>]
   [-SortBy <String>]

You may query specific properties of the Office 365 group objects:

Get-UnifiedGroup | Format-List Alias, EmailAddresses, WhenCreated, WhenChanged, SharePointSiteUrl

To get the display name and Primary SMTP Addresses (primary email address), use the Get-UnifiedGroup cmdlet as Pipeline input:

Get-UnifiedGroup -ResultSize Unlimited | Select-Object DisplayName,PrimarySmtpAddress

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

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

To get the Owners and Members of Microsoft 365 groups, use the Get-UnifiedGroupLinks cmdlet.

PnP PowerShell to Get All Microsoft 365 Groups

The below PnP PowerShell script gets all Microsoft 365 groups in your tenant and exports group 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 = ""
$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
    #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

#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

In summary, by following these simple steps, you can quickly get a list of all Office 365 groups in your organization using the Microsoft 365 admin center or PowerShell. This can be useful for various purposes, such as auditing, reporting, or management.

Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two-decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. He has held various positions including SharePoint Architect, Administrator, Developer and consultant, has helped many organizations to implement and optimize SharePoint solutions. Known for his deep technical expertise, He's passionate about sharing the knowledge and insights to help others, through the real-world articles!

Leave a Reply

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