Using Update-MgTeam in Graph PowerShell

The Update-MgTeam cmdlet allows administrators to update settings for an existing Microsoft Team. This is essential for maintaining consistent team management policies, enabling or disabling features for users, and making large-scale updates efficiently.

Cmdlet Syntax

Update-MgTeam -TeamId <String> [-BodyParameter <Hashtable>]
  • TeamId: The unique identifier of the team you want to update (required).
  • BodyParameter: Contains the properties that need updating, formatted as a hashtable.

Usage Examples

Example 1: Adjusting Team Settings

$params = @{
    memberSettings = @{
        allowCreateUpdateChannels = $true
    }
    messagingSettings = @{
        allowUserEditMessages = $true
        allowUserDeleteMessages = $true
    }
    funSettings = @{
        allowGiphy = $true
        giphyContentRating = "strict"
    }
}

$teamId = "your-team-id"
Update-MgTeam -TeamId $teamId -BodyParameter $params

This example shows how to update a single team by changing member messaging and fun settings.

Example 2: Modifying Settings for Multiple Teams

$teamIds = @("teamId1", "teamId2", "teamId3")

# Update settings for each team
$params = @{
    memberSettings = @{
        allowCreateUpdateChannels = $true
    }
    messagingSettings = @{
        allowUserEditMessages = $true
        allowUserDeleteMessages = $true
    }
    funSettings = @{
        allowGiphy = $true
        giphyContentRating = "strict"
    }
}

foreach ($teamId in $teamIds) {
    Update-MgTeam -TeamId $teamId -BodyParameter $params
    Write-Host "Updated team with ID: $teamId"
}

Example 3: Bulk Updates via CSV

TeamId,AllowCreateUpdateChannels,AllowUserEditMessages,AllowUserDeleteMessages
team-id-1,true,true,true
team-id-2,false,false,true

To update multiple teams using a CSV file, the following script will read the CSV and apply updates for each team:

$csv = Import-Csv -Path "C:\path\to\teams.csv"

foreach ($team in $csv) {
    $params = @{
        memberSettings = @{
            allowCreateUpdateChannels = [bool]::Parse($team.AllowCreateUpdateChannels)
        }
        messagingSettings = @{
            allowUserEditMessages = [bool]::Parse($team.AllowUserEditMessages)
            allowUserDeleteMessages = [bool]::Parse($team.AllowUserDeleteMessages)
        }
    }

    Update-MgTeam -TeamId $team.TeamId -BodyParameter $params
}

Cmdlet Tips

  • Retrieve the Correct TeamId: Ensure that you retrieve the correct TeamId by using the Get-MgTeam cmdlet.
  • Bulk Updates via CSV: If you plan to apply the same settings to multiple teams, bulk updating via CSV can save a lot of time.
  • Use Hashtables: Use hashtables in -BodyParameter to neatly structure your updates and avoid errors.

Use Cases

  • Managing Large Teams with Varying Permissions: Organizations often have different teams with distinct needs. With Update-MgTeam, administrators can enable or disable key features (like allowing users to create channels or edit messages) on a team-by-team basis to align with company policies.
  • Automating Compliance-Related Changes: Teams within organizations may need to comply with different policies based on their sensitivity level. For example, strict fun settings or restricted message deletion could be applied automatically across specific teams handling confidential projects.
  • Regular Updates to Multiple Teams: Using the CSV bulk update method, you can schedule regular updates for multiple teams at once, ensuring that all team settings are up to date without manual intervention.

Possible Errors & Solutions

Error Cause Solution
Team Not Found The TeamId provided might be incorrect or the team doesn't exist. Verify the TeamId by running Get-MgTeam. Ensure that the team is part of your Microsoft 365 organization.
Invalid BodyParameter Structure The hashtable provided in -BodyParameter is incorrectly structured. Ensure that you use the correct property names and value formats according to Microsoft Graph API documentation. Validate with a small test team before rolling out to production.
Insufficient Permissions The account running the script doesn’t have sufficient permissions to update the team. Ensure that your account has the required Teams Administrator role in Microsoft 365.

Conclusion

The Update-MgTeam cmdlet is an invaluable tool for managing team settings across Microsoft Teams. With its flexibility, administrators can make single or bulk updates efficiently, maintaining control over how teams operate within the organization. By combining it with CSV files, this process becomes even more streamlined, making it an essential tool for Microsoft 365 administration.

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