Using Get-MgTeam with Update-MgTeam: Managing Microsoft Teams Settings

Microsoft Teams is an essential tool for collaboration in modern workplaces. Pairing Get-MgTeam and Update-MgTeam allows administrators to retrieve details about a Team and modify its settings programmatically. This article provides an example, tips, and use cases for leveraging these cmdlets effectively.

The Get-MgTeam cmdlet retrieves details about a specific Microsoft Team, such as its display name, description, and settings. The Update-MgTeam cmdlet allows administrators to modify Team properties, such as member permissions, guest access, and messaging settings. Together, these cmdlets are powerful tools for managing Teams at scale, ensuring compliance with organizational policies, and streamlining collaboration.

Usage Example: Updating Team Member Permissions

Here’s how to retrieve a Team’s settings and update its member permissions:


# Step 1: Retrieve the Team by display name
$teamName = "Marketing Team"  # Replace with your Team's display name

$team = Get-MgTeam -Filter "displayName eq '$teamName'"

if ($team -ne $null) {
    Write-Output "Team Found: $($team.DisplayName)"
    Write-Output "Team ID: $($team.Id)"
} else {
    Write-Error "Team not found."
    return
}

# Step 2: Update member permissions for the Team
$updatedSettings = @{
    MemberSettings = @{
        AllowCreateUpdateChannels = $false
        AllowDeleteChannels = $false
    }
}

try {
    Update-MgTeam -TeamId $team.Id -BodyParameter $updatedSettings
    Write-Output "Team settings updated successfully."
} catch {
    Write-Error "Failed to update Team settings: $_"
}
                            

Cmdlet Tips

  • Retrieve Teams Efficiently: Use Get-MgTeam with the -Filter parameter to locate specific Teams by properties like displayName or description:
  • 
    Get-MgTeam -Filter "displayName eq 'Finance Team'"
                                    
  • Understand the Settings Schema: Familiarize yourself with the Microsoft Teams settings schema to understand which properties are modifiable. For example:
    • GuestSettings: Controls guest access permissions.
    • MemberSettings: Manages member permissions like creating channels.
    • MessagingSettings: Configures messaging capabilities within the Team.
  • Partial Updates: When using Update-MgTeam, specify only the properties you want to modify. Unspecified properties remain unchanged.
  • Bulk Updates: To apply the same settings to multiple Teams, loop through a list of Teams and use Update-MgTeam:
  • 
    $teams = Get-MgTeam -Filter "displayName startswith 'Project'"
    foreach ($team in $teams) {
        Update-MgTeam -TeamId $team.Id -BodyParameter $updatedSettings
    }
                                    
  • Testing Changes: Apply updates to a test Team before deploying changes to production Teams.

Use Cases

  1. Enforcing Governance Policies: Ensure that all Teams comply with organizational policies by restricting member and guest permissions, disabling channel deletion, or setting messaging limits.
  2. Streamlining Team Management: Automate updates to Teams settings during organizational changes, such as departmental restructuring or policy updates.
  3. Standardizing Team Configurations: Apply consistent settings across Teams to maintain uniformity in permissions, guest access, and collaboration tools.
  4. Bulk Updates for Projects: Manage settings for project-specific Teams, ensuring they adhere to the required security and compliance standards.
  5. Auditing and Reporting: Retrieve and audit Team settings to ensure compliance with organizational or regulatory requirements.

Possible Errors & Solutions

Error Cause Solution
Team Not Found Team does not exist or incorrect display name Verify the Team's existence using Get-MgTeam.
Access Denied Insufficient permissions Assign TeamSettings.ReadWrite.All permissions in Azure AD.
Invalid Property Attempting to modify a read-only property Check the Microsoft Teams settings schema for modifiable properties.
Too Many Requests API throttling due to bulk updates Implement retries with exponential backoff.
JSON Schema Error Malformed JSON payload in -BodyParameter Ensure the JSON adheres to the required schema for Teams updates.

Conclusion

Pairing Get-MgTeam and Update-MgTeam provides administrators with the ability to manage Teams programmatically, enhancing collaboration and ensuring compliance with organizational policies. From configuring member permissions to enforcing governance rules, these cmdlets streamline Teams management and help maintain a secure, productive environment.

By leveraging these cmdlets effectively, administrators can save time, reduce errors, and ensure Teams are configured to meet organizational needs.

Suggested Reading

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