Using Get-MgGroup with Update-MgGroup: Manage Microsoft 365 Groups

Microsoft 365 Groups play a central role in collaboration and resource access across Microsoft 365 services. By pairing Get-MgGroup and Update-MgGroup, administrators can retrieve group details and update their properties efficiently. This article outlines how to use these cmdlets together, providing a practical example, tips, and troubleshooting guidance.

The Get-MgGroup cmdlet retrieves detailed information about groups, including their display name, description, and membership type. The Update-MgGroup cmdlet allows you to modify properties like group names, descriptions, and settings. Combining these cmdlets enables administrators to automate updates, enforce naming conventions, or standardize group configurations.

Usage Example: Updating a Group's Description


# Step 1: Retrieve the group by display name
$groupName = "Marketing Team"  # Replace with the group's display name
$group = Get-MgGroup -Filter "displayName eq '$groupName'"

if ($group -ne $null) {
    Write-Output "Group Found: $($group.DisplayName)"
    Write-Output "Current Description: $($group.Description)"
} else {
    Write-Error "Group not found."
    return
}

# Step 2: Update the group's description
$updatedProperties = @{
    Description = "This group is for all members of the Marketing Department."
}

Update-MgGroup -GroupId $group.Id -BodyParameter $updatedProperties
Write-Output "Group description updated successfully."
                            

Cmdlet Tips

  • Filter Groups Efficiently: Use the -Filter parameter with Get-MgGroup to retrieve specific groups based on properties like displayName:
    Get-MgGroup -Filter "groupTypes/any(c:c eq 'Unified')"
  • Partial Updates: When using Update-MgGroup, include only the properties you want to update. Unspecified properties will remain unchanged.
  • Verify Group Details Before Updating: Always review the group’s current details (e.g., name or description) before making changes to avoid accidental modifications.
  • Automate Naming Conventions: Use scripts to enforce naming conventions, such as prefixing department names to group display names:
    $groupPrefix = "Dept-"
    Update-MgGroup -GroupId $group.Id -BodyParameter @{ DisplayName = "$groupPrefix$($group.DisplayName)" }

Use Cases

  1. Standardizing Group Configurations: Automate the process of updating group descriptions, display names, or policies across multiple groups.
  2. Enforcing Naming Conventions: Ensure consistent naming conventions for all groups to improve discoverability and management.
  3. Bulk Updates for Reorganization: Update multiple groups during organizational restructuring or departmental changes.
  4. Governance and Compliance: Modify group settings to align with compliance policies or IT governance standards.

Possible Errors & Solutions

Error Message Cause Solution
Group Not Found Group name or ID does not match any existing group Verify the group name or filter criteria.
Access Denied Insufficient permissions Assign appropriate permissions like Group.ReadWrite.All.
Property Not Supported for Update Attempting to update a read-only property Check the Microsoft Graph schema to confirm writable properties.
Invalid JSON in -BodyParameter Malformed JSON payload Ensure the payload adheres to the correct schema and syntax.

Conclusion

Pairing Get-MgGroup and Update-MgGroup allows administrators to manage Microsoft 365 Groups efficiently. Whether you’re standardizing group properties, automating updates, or implementing compliance policies, these cmdlets provide the flexibility and control you need.

By following best practices and leveraging the power of Microsoft Graph PowerShell, you can streamline group management workflows and enhance collaboration across your organization.

Suggested Reading

© m365corner.com. All Rights Reserved. Design by HTML Codex