This guide provides an overview of managing Microsoft 365 groups using Microsoft Graph PowerShell. Learn how to retrieve, update and delete groups with practical examples for efficient group management.
The Get-MgGroup cmdlet is a powerful tool in the Microsoft Graph PowerShell module, allowing administrators to retrieve information about groups in Microsoft 365. In this article, we will explore its syntax, provide usage examples, discuss common errors, and offer some tips for effective usage.
The basic syntax for the Get-MgGroup cmdlet is as follows:
Get-MgGroup [-GroupId <String>] [-Filter <String>] [-Search <String>] [-Property <String[]>] [-ConsistencyLevel <String>] [-Top <Int32>] [-Skip <Int32>] [-All] [<CommonParameters>]
Get-MgGroup -GroupId "5b34b8a4-6e77-4d8a-94eb-9b150d938f97"
This example retrieves details of a group specified by its ID.
Get-MgGroup -All
This example retrieves all groups in the organization.
Get-MgGroup -Filter "DisplayName eq 'Marketing'"
This example retrieves groups with the display name "Marketing".
Get-MgGroup -All -Property Id, DisplayName, GroupTypes
This example retrieves all groups and displays only the Id, DisplayName, and GroupTypes properties.
Get-MgGroup -Search "displayName:Project"
This example searches for groups whose display names contain the string "Project".
(Get-MgGroup -All).Count
This example retrieves the count of all groups in the organization.
Connect-MgGraph
cmdlet with appropriate scopes such as Group.Read.All
.-Filter
and -Search
parameters to narrow down results, improving performance and relevance.-Property
parameter to retrieve only the necessary properties, reducing the payload size.-Top
, -Skip
, and -All
parameters to handle large datasets efficiently.-ConsistencyLevel eventual
parameter to ensure eventual consistency for large queries.1. What is MgGroup used for in Microsoft Graph PowerShell?
MgGroup cmdlets in Microsoft Graph PowerShell are used to manage Microsoft 365 groups. They support operations like creating, updating, retrieving, and deleting groups within a tenant.
2. How can I retrieve all Microsoft 365 groups?
Use the following script to retrieve all groups:
Get-MgGroup -All
3. Can I update a group’s properties using MgGroup cmdlets?
Yes, you can use the Update-MgGroup cmdlet. Example:
$Body = @{
displayName = "Updated Group Name"
description = "Updated Description"
}
Update-MgGroup -GroupId "<GroupId>" -BodyParameter $Body
4. How can I delete a Microsoft 365 group?
To delete a group, use the Remove-MgGroup cmdlet:
Remove-MgGroup -GroupId "<GroupId>"
The Get-MgGroup cmdlet is an essential tool for managing and retrieving group information in Microsoft 365 using Microsoft Graph PowerShell. By understanding its syntax, using practical examples, handling common errors, and applying best practices, administrators can leverage this cmdlet to streamline their group management tasks effectively.
For more detailed information, refer to the official Microsoft documentation.
© m365corner.com. All Rights Reserved. Design by HTML Codex