🔧 New: User Management Graph PowerShell Toolkit

Simplify user tasks like bulk creation, updates, password resets, deletions, license checks & more — all from one place.

🚀 Launch Toolkit

Get-MgGroup – The Complete Guide

Managing groups in Microsoft 365 is a vital part of administration, especially when you’re dealing with hundreds or thousands of users. Whether you’re organizing distribution lists, managing Microsoft Teams, or handling security permissions, groups play a central role in how information and collaboration flow across your tenant.

The Get-MgGroup cmdlet from Microsoft Graph PowerShell makes it easy to retrieve, search, and filter groups efficiently — all from your PowerShell console.


What is Get-MgGroup?

The Get-MgGroup cmdlet retrieves information about Microsoft 365 groups (also called Microsoft Entra groups) from your tenant using Microsoft Graph PowerShell.

With it, you can:

  • View all groups in your organization
  • Get details of specific groups
  • Filter groups based on type, name, or other properties
  • Integrate group data into automation scripts

Whether you’re an IT admin or a PowerShell enthusiast, this cmdlet gives you quick access to everything you need to manage your groups efficiently.


Why use Get-MgGroup?

Microsoft is gradually replacing older PowerShell modules like MSOnline and AzureAD with the Microsoft Graph PowerShell module.

Here’s why you should switch to Get-MgGroup:

  • ✅ Future-proof – Microsoft Graph is the modern API layer for Microsoft 365.
  • ✅ Unified Access – Works for all types of groups — Microsoft 365 (Unified), Security, and Distribution.
  • ✅ Powerful Filtering – Easily find groups by department, name, or creation date.
  • ✅ Supports Automation – Integrates smoothly with scripts for reporting and management tasks.

How to use Get-MgGroup?

Here’s the basic syntax of the cmdlet:

Get-MgGroup -GroupId "<group-id>"
Parameter Description
-GroupId Specifies the group to retrieve by its unique ID.
-All Retrieves all groups from the tenant.
-Filter Allows you to narrow results using OData filters (e.g., DisplayName eq 'Marketing').
-Search Lets you search for groups containing a specific string in their name.
-Property Retrieves specific properties of the group.


Get-MgGroup Examples

Example 1: Get a Specific Group by ID

Get-MgGroup -GroupId "5b34b8a4-6e77-4d8a-94eb-9b150d938f97"

This example retrieves details of a group specified by its ID.

Example 2: List All Groups

Get-MgGroup -All

This example retrieves all groups in the organization.

Example 3: Filter Groups by Display Name

Get-MgGroup -Filter "DisplayName eq 'Marketing'"

This example retrieves groups with the display name “Marketing.”

Example 4: Select Specific Properties of All Groups

Get-MgGroup -All -Property Id, DisplayName, GroupTypes

This example retrieves all groups and displays only the Id, DisplayName, and GroupTypes properties.

Example 5: Search for Groups Containing a Specific String

Get-MgGroup -Search "displayName:Project"

This example searches for groups whose display names contain the string “Project.”

Example 6: Get the Count of All Groups

(Get-MgGroup -All).Count

This example retrieves the total number of groups in the organization.

Example 7: Get the Created Date of All Groups

Get-MgGroup -All | Select-Object DisplayName, CreatedDateTime | Sort-Object CreatedDateTime

This example retrieves the names and creation dates of all groups and sorts them by the creation date.


Get-MgGroup Cmdlet Usage in Scripts

Let’s look at two practical examples where Get-MgGroup can make real administrative tasks faster and easier.

Fetch Unified Groups in the Tenant


# Connect to Microsoft Graph
Connect-MgGraph -Scopes "Group.Read.All"

# Retrieve only Unified (Microsoft 365) groups
$UnifiedGroups = Get-MgGroup -All | Where-Object {
    $_.GroupTypes -contains "Unified"
}

# Display the results
$UnifiedGroups | Select DisplayName, Mail, Visibility, CreatedDateTime

How it works:

  • Connects to Microsoft Graph with the necessary scope.
  • Retrieves all groups from the tenant.
  • Filters groups where the GroupTypes property contains "Unified", which identifies Microsoft 365 (M365) groups.
  • Outputs the display name, email address, visibility (Public/Private), and creation date for clarity.

🔍 Note: Unified groups power Microsoft Teams, Planner, and SharePoint collaboration workspaces, so this script is particularly useful for M365 group audits.


Fetch Distribution Groups in the Tenant


# Connect to Microsoft Graph
Connect-MgGraph -Scopes "Group.Read.All"
                                
# Retrieve only distribution lists (mail-enabled, NOT security or unified groups)
$distributionLists = Get-MgGroup -All | Where-Object {
    $_.MailEnabled -eq $true -and
    $_.SecurityEnabled -eq $false -and
    ($_.GroupTypes -eq $null -or $_.GroupTypes.Count -eq 0)
}                        
# Output results
$distributionLists | Select DisplayName, Mail, Id

How it works:

  • Connects to Microsoft Graph using the required permission scope.
  • Retrieves all groups.
  • Filters groups that are mail-enabled, not security-enabled, and don’t have a GroupType (which means they’re distribution lists).
  • Displays each group’s name, email, and ID.

💡 Tip: You can export the results to CSV using Export-Csv for reporting.


Conclusion

The Get-MgGroup cmdlet is a must-have tool in every Microsoft 365 administrator’s toolkit. It gives you instant visibility into your organization’s group structure — whether it’s Microsoft 365, distribution, or security groups.

With examples like filtering groups, fetching creation dates, and listing Unified or Distribution groups, you can streamline reporting and automate repetitive group management tasks.

🚀 Pro Tip: Combine Get-MgGroup with cmdlets like Get-MgGroupMember and Get-MgGroupOwner to build advanced reports and get a complete view of group ownership and membership.


Did You Know? Managing Microsoft 365 applications is even easier with automation. Try our Graph PowerShell scripts to automate tasks like generating reports, cleaning up inactive Teams, or assigning licenses efficiently.

Ready to get the most out of Microsoft 365 tools? Explore our free Microsoft 365 administration tools to simplify your administrative tasks and boost productivity.

© Your Site Name. All Rights Reserved. Design by HTML Codex