The New-MgTeamMember cmdlet in Microsoft Graph PowerShell is used to add users (members or owners) to a Microsoft Team programmatically. It allows administrators to manage team memberships efficiently without relying on the Teams Admin Center. This cmdlet supports both individual and bulk member additions using PowerShell automation.
Adding members manually to multiple Teams can be time-consuming. The New-MgTeamMember cmdlet enables automation, allowing administrators to:
Before running the cmdlet, connect to Microsoft Graph with the required permission scope:
Connect-MgGraph -Scopes "TeamMember.ReadWrite.All"
You must also have administrative privileges or the appropriate delegated permissions to manage Teams memberships.
You can use this cmdlet by specifying the TeamId and BodyParameter (which defines user details such as roles and binding).
New-MgTeamMember -TeamId <String> -BodyParameter <IMicrosoftGraphAADUserConversationMember>
This example adds a user as an owner to a specific team.
$params = @{
"@odata.type" = "#microsoft.graph.aadUserConversationMember"
roles = @("owner")
"user@odata.bind" = "https://graph.microsoft.com/v1.0/users('8b081ef6-4792-4def-b2c9-c363a1bf41d5')"
}
New-MgTeamMember -TeamId "72a1f6b2-5829-4f26-b3a4-738b4848e248" -BodyParameter $params
This example adds multiple users—one as an owner and another as a member.
$teamId = "72a1f6b2-5829-4f26-b3a4-738b4848e248"
$members = @(
@{
"@odata.type" = "#microsoft.graph.aadUserConversationMember"
roles = @("owner")
"user@odata.bind" = "https://graph.microsoft.com/v1.0/users('8b081ef6-4792-4def-b2c9-c363a1bf41d5')"
}
@{
"@odata.type" = "#microsoft.graph.aadUserConversationMember"
roles = @()
"user@odata.bind" = "https://graph.microsoft.com/v1.0/users('9f0e769d-8df1-44f8-bc17-dc7f8881d546')"
}
)
foreach ($member in $members) {
New-MgTeamMember -TeamId $teamId -BodyParameter $member
}
This example shows how to add users in bulk by importing details from a CSV file.
CSV Format:
UserId,Role
8b081ef6-4792-4def-b2c9-c363a1bf41d5,owner
9f0e769d-8df1-44f8-bc17-dc7f8881d546,member
PowerShell Script:
$teamId = "72a1f6b2-5829-4f26-b3a4-738b4848e248"
$csvPath = "C:\path\to\your\file.csv"
$users = Import-Csv -Path $csvPath
foreach ($user in $users) {
$params = @{
"@odata.type" = "#microsoft.graph.aadUserConversationMember"
roles = @($user.Role)
"user@odata.bind" = "https://graph.microsoft.com/v1.0/users('$($user.UserId)')"
}
New-MgTeamMember -TeamId $teamId -BodyParameter $params
}
This approach is ideal for large organizations needing to add multiple members efficiently.
| Key Point | Details |
|---|---|
| Cmdlet Name | New-MgTeamMember |
| Purpose | Adds users (members or owners) to a Microsoft Team |
| Required Scope | TeamMember.ReadWrite.All |
| Primary Parameter | TeamId, BodyParameter |
| Automation Benefit | Automates team membership management and reduces manual errors |
| Use Case | Ideal for adding members or owners individually or in bulk across Teams |
Did You Know? Managing Microsoft 365 applications is even easier with automation. Try our Graph PowerShell scripts to automate tasks like generating reports, cleaning up inactive Teams, or assigning licenses efficiently.
Ready to get the most out of Microsoft 365 tools? Explore our free Microsoft 365 administration tools to simplify your administrative tasks and boost productivity.
© Your Site Name. All Rights Reserved. Design by HTML Codex