How to Use Get-MgGroup to Fetch Microsoft 365 Groups

Microsoft 365 administrators often need to retrieve details about groups within their tenant for reporting, auditing, or management purposes. The Get-MgGroup cmdlet, part of the Microsoft Graph PowerShell module, allows you to fetch group details efficiently using various filters and search parameters.

What is Get-MgGroup?

The Get-MgGroup cmdlet is used to retrieve information about Microsoft 365 groups, including security groups, distribution lists, and Microsoft Teams groups. This cmdlet provides detailed insights into group properties such as display name, description, membership type, and more.

Why Use Get-MgGroup?

Admins use Get-MgGroup for various purposes, including:

  • Monitoring group details – Retrieve essential group attributes like name, description, and type.
  • Filtering specific groups – Fetch groups based on specific criteria, such as display name.
  • Counting groups – Determine the number of groups that meet a certain condition.
  • Sorting group results – Retrieve and order groups by a specific property.

By leveraging Get-MgGroup, administrators can efficiently manage and report on Microsoft 365 groups.

Cmdlet Syntax

Below is the basic syntax of the Get-MgGroup cmdlet:

Get-MgGroup [-GroupId <String>] [-Filter <String>] [-Search <String>] [-ConsistencyLevel <String>] 
  • -GroupId: Fetch details of a specific group using its unique identifier.
  • -Filter: Apply a filter condition to fetch groups that meet specific criteria.
  • -Search: Perform a search query within the group attributes.
  • -OrderBy: Sort the results based on a specific property.
  • -ConsistencyLevel eventual: Enables advanced filtering and counting.
  • -CountVariable: Stores the count of returned groups in a variable.

Usage Examples

Here are practical examples of how to use Get-MgGroup:

  1. Retrieve All Microsoft 365 Groups
  2. Get-MgGroup

    This command fetches all groups available in the tenant.

  3. Get Details of a Specific Group by ID
  4. Get-MgGroup -GroupId "143baf7e-406b-49b5-ac25-13174ddf1515"

    This retrieves detailed information about the group with the specified ID.

  5. Find a Group by Display Name
  6. Get-MgGroup -Filter "DisplayName eq 'Kitchen Team'"

    This command fetches the group whose display name exactly matches 'Kitchen Team'.
  7. Fetch Specific Properties of a Group
  8. Get-MgGroup -Filter "DisplayName eq 'MSFT'" | Format-List Id, DisplayName, Description, GroupTypes

    This retrieves and displays only selected properties of the group named 'MSFT'.

  9. Perform a Search Query for a Group
  10. Get-MgGroup -ConsistencyLevel eventual -Count groupCount -Search '"DisplayName:Team2001"'

    This searches for groups where the display name includes 'Team2001' and counts the matching results.

  11. Retrieve Groups Starting with a Specific Letter
  12. Get-MgGroup -ConsistencyLevel eventual -Count groupCount -Filter "startsWith(DisplayName, 'S')" 

    This command retrieves all groups whose names start with the letter 'S', counts them, and sorts the results by display name.


Frequently Asked Questions

  1. Why is my Get-MgGroup query returning limited results?
  2. By default, Microsoft Graph limits responses to 100 results. To fetch all groups, use:

    Get-MgGroup -All
  3. How can I retrieve only security groups?
  4. Use the -Filter parameter to filter for security-enabled groups:

    Get-MgGroup -Filter "SecurityEnabled eq true"
  5. What permissions are required to use Get-MgGroup?
  6. You need Group.Read.All or Group.ReadWrite.All permissions in Microsoft Graph.
  7. Why do I need ConsistencyLevel eventual?
  8. The ConsistencyLevel eventual parameter is required when using advanced filtering or counting (-Count).

Use Cases

  1. Auditing Group Memberships
  2. Admins can generate reports on all groups and their properties for auditing and compliance.

  3. Identifying Inactive Groups
  4. Use filters to find groups without recent activity and review their necessity.

  5. Sorting and Searching Groups for Easier Management
  6. Using search and sorting parameters, administrators can locate groups efficiently.

Conclusion

The Get-MgGroup cmdlet is an essential tool for Microsoft 365 administrators to retrieve and manage groups efficiently. Whether you're performing audits, searching for specific groups, or filtering results based on attributes, Get-MgGroup provides the flexibility and power needed for effective group management

By mastering these commands and examples, you can streamline your Microsoft 365 administration tasks with ease!

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