This article provides a step-by-step guide to using the Update-MgGroup cmdlet in Microsoft Graph PowerShell. Learn how to modify Microsoft 365 group properties, such as display name, description, and visibility, with examples for single and bulk updates
The Update-MgGroup cmdlet in the Microsoft Graph PowerShell module allows administrators to modify the properties of existing Microsoft 365 groups. This article will guide you through the prerequisites, cmdlet syntax, usage examples, tips, common errors, and solutions for the Update-MgGroup cmdlet.
Install-Module Microsoft.Graph -Scope CurrentUser
Connect-MgGraph -Scopes "Group.ReadWrite.All"
Update-MgGroup -GroupId <String> [-DisplayName <String>] [-Description <String>] [-MailNickname <String>] [-Visibility <String>] [-SecurityEnabled <Boolean>] [-MailEnabled <Boolean>] [-WhatIf] [-Confirm] []
-GroupId:
(Required) The ID of the group to update.-DisplayName:
(Optional) The new display name for the group.-Description:
(Optional) The new description for the group.-Visibility:
(Optional) The new visibility setting for the group (Public or Private).-SecurityEnabled:
(Optional) Specifies if the group is a security group.-MailEnabled:
(Optional) Specifies if the group is mail-enabled.-WhatIf:
(Optional) Shows what would happen if the cmdlet runs. The cmdlet is not executed.-Confirm:
(Optional) Prompts for confirmation before executing the cmdlet.You should pass in the new display name and description along with Group ID.
Update-MgGroup -GroupId "12345678-90ab-cdef-1234-567890abcdef" -DisplayName "New Group Name" -Description "Updated group description"
You should pass in the new group visibility along with Group ID.
Update-MgGroup -GroupId "12345678-90ab-cdef-1234-567890abcdef" -Visibility Private
You should use New-MgGroupMember cmdlet to add or update members of a group
$members = @("8a7c50d3-fcbd-4727-a889-8ab232dfea01", "9a6d50d3-fcbd-4727-a889-8ab232dfea02")
foreach ($member in $members) {
New-MgGroupMember -GroupId "12345678-90ab-cdef-1234-567890abcdef" -DirectoryObjectId $member
}
You should use Remove-MgGroupMemberByRef cmdlet to remove members from a group
$members = @("8a7c50d3-fcbd-4727-a889-8ab232dfea01", "9a6d50d3-fcbd-4727-a889-8ab232dfea02")
foreach ($member in $members) {
Remove-MgGroupMemberByRef -GroupId "12345678-90ab-cdef-1234-567890abcdef" -DirectoryObjectId $member
}
You should use New-MgGroupOwner cmdlet to add or update members of a group
$members = @("8a7c50d3-fcbd-4727-a889-8ab232dfea01", "9a6d50d3-fcbd-4727-a889-8ab232dfea02")
foreach ($member in $members) {
New-MgGroupOwner -GroupId "12345678-90ab-cdef-1234-567890abcdef" -DirectoryObjectId $member
}
You should use Remove-MgGroupOwnerByRef cmdlet to owners from a group
$members = @("8a7c50d3-fcbd-4727-a889-8ab232dfea01", "9a6d50d3-fcbd-4727-a889-8ab232dfea02")
foreach ($member in $members) {
Remove-MgGroupOwnerByRef -GroupId "12345678-90ab-cdef-1234-567890abcdef" -DirectoryObjectId $member
}
To change the mail nickname (alias) of a Microsoft 365 group, execute the following command:
Update-MgGroup -GroupId "12345678-90ab-cdef-1234-567890abcdef" -MailNickname "NewAlias"
Note:Modifying the mail nickname affects the group's email address, so ensure the new alias aligns with your organization's naming conventions.
To configure a group's mail-enabled and security-enabled settings, use:
Update-MgGroup -GroupId "12345678-90ab-cdef-1234-567890abcdef" -MailEnabled $true -SecurityEnabled $false
This command enables the group to receive emails while disabling its security group capabilities.
You should do the following to update a group using Microsoft 365 admin center:
-WhatIf
parameter to see what changes will be made without actually applying them.Error | Cause | Solution |
ResourceNotFound | The specified Group ID does not exist. | Verify the Group ID and try again. Use Get-MgGroup cmdlet to verify group id. |
InsufficientPrivileges | The user does not have sufficient privileges to update the group. | Ensure you have the necessary permissions and try again. Group.ReadWrite.All is the Graph API permission you need. |
InvalidRequest | One or more parameters are invalid. | Check the parameter values and ensure they meet the requirements. |
Always include a try-catch block within your scripts so that you can catch errors successfully.
try {
Update-MgGroup -GroupId "12345678-90ab-cdef-1234-567890abcdef" -DisplayName "New Group Name"
} catch {
Write-Host "An error occurred: $_"
}
Update-MgGroup is a Microsoft Graph PowerShell cmdlet used to modify properties of Microsoft 365 groups, such as display name, description, visibility, and membership settings.
You can update a group’s properties using the -BodyParameter parameter:
$Body = @{
"displayName" = "New Group Name"
"description" = "Updated group description"
}
Update-MgGroup -GroupId "" -BodyParameter $Body
Prepare a CSV file with the following format:
GroupId,DisplayName,Description
,New Group Name 1,Updated Description 1
,New Group Name 2,Updated Description 2
Use this script to process the CSV and update group properties:
$Groups = Import-Csv -Path "C:\Path\To\File.csv"
foreach ($Group in $Groups) {
$Body = @{
"displayName" = $Group.DisplayName
"description" = $Group.Description
}
Update-MgGroup -GroupId $Group.GroupId -BodyParameter $Body
}
You can modify multiple properties in a single Update-MgGroup command by specifying each property and its new value. For example:
Update-MgGroup -GroupId "12345678-90ab-cdef-1234-567890abcdef" -DisplayName "New Group Name" -Description "Updated Description" -Visibility "Private"
This command updates the group's display name, description, and visibility settings simultaneously.
To execute the Update-MgGroup cmdlet, your account must have the Group.ReadWrite.All permission in Microsoft Graph. Additionally, you should have administrative roles such as User Administrator or Global Administrator in Azure Active Directory to modify group properties. Ensure you connect to Microsoft Graph with the necessary scopes:
Connect-MgGraph -Scopes "Group.ReadWrite.All"
By integrating these additional examples and FAQs, your article will provide a more comprehensive guide to managing Microsoft 365 groups using the Update-MgGroup cmdlet.
Update-MgGroup
.-BodyParameter
hashtable — others will remain unaffected.description
field for a Microsoft 365 group, note that it must not exceed 256 characters.BadRequest
error.
The Update-MgGroup cmdlet is a versatile tool for managing Microsoft 365 groups' properties. To manage group members, use the New-MgGroupMember and Remove-MgGroupMember cmdlets. By understanding these cmdlets and their usage, administrators can efficiently manage group properties and memberships. Always test changes with the -WhatIf
parameter and handle errors to ensure smooth operations.
For more detailed information, refer to the Microsoft Graph PowerShell Update-MgGroup documentation.
© m365corner.com. All Rights Reserved. Design by HTML Codex