New-MgTeamMember

What is New-MgTeamMember?

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.


Why Use New-MgTeamMember?

Adding members manually to multiple Teams can be time-consuming. The New-MgTeamMember cmdlet enables automation, allowing administrators to:

  • Quickly add or assign owners to one or more Teams.
  • Bulk import members from CSV files for large-scale management.
  • Streamline onboarding of new employees into Teams automatically.
This cmdlet enhances productivity and ensures accuracy in Microsoft Teams membership management.

Prerequisites

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.


How to Use New-MgTeamMember?

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>

New-MgTeamMember Examples

Example 1: Adding a Single User to a Team

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

Example 2: Adding Multiple Users to a Team

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
}

Example 3: Adding Users to a Team from a CSV File

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.


Summary

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