πŸ”§ New: User Management Graph PowerShell Toolkit

Simplify user tasks like bulk creation, updates, password resets, deletions, license checks & more β€” all from one place.

πŸš€ Launch Toolkit

Bulk Import Microsoft Teams Members Using Graph PowerShell and CSV

Managing team memberships manually can be tedious, especially when onboarding multiple users across departments or projects. With Microsoft Graph PowerShell, you can automate the process and bulk add members to Teams using just a CSV file. This article walks you through the process with a simple, reliable script.


i) The Script: Bulk Add Members to Teams from CSV

# Connect to Microsoft Graph with necessary permissions
Connect-MgGraph -Scopes "TeamMember.ReadWrite.All"
                                
# Import the CSV file
$members = Import-Csv -Path "members.csv"
                                
foreach ($entry in $members) {
    $teamId = $entry.TeamId
    $userId = $entry.UserId
                                
    # Prepare body parameters for each member
    $params = @{
        "@odata.type"     = "#microsoft.graph.aadUserConversationMember"
        roles             = @()  # All users added as members
        "user@odata.bind" = "https://graph.microsoft.com/v1.0/users('$userId')"
    }
                                
    try {
        New-MgTeamMember -TeamId $teamId -BodyParameter $params
        Write-Host "βœ… Added user '$userId' to team '$teamId'" -ForegroundColor Green
    } catch {
        Write-Host "❌ Failed to add user '$userId': $_" -ForegroundColor Red
    }
}

Sample CSV File (members.csv)

TeamId,UserId
7c564b30-bb67-48df-b7cb-cfb60f2cf5a3,fa25cbd9-bbe4-4d1a-aaa3-e7f7c23828b5
7c564b30-bb67-48df-b7cb-cfb60f2cf5a3,20f85e5b-813a-4b75-83f5-69d15b7cf437
  • TeamId: The ID of the Microsoft Team (backed by a Microsoft 365 Group)
  • UserId: The Azure AD Object ID of the user

Use Get-MgTeam and Get-MgUser to fetch these values.


ii) How the Script Works

  1. Connects to Microsoft Graph using the required scope TeamMember.ReadWrite.All.
  2. Loads a CSV file hat lists each TeamId and corresponding UserId to be added.
  3. Iterates over each row and builds a request payload with:
    • The user’s Object ID bound to the Graph URI
    • Role set to member (default)
  4. Calls New-MgTeamMember to add the user to the specified team.
  5. Outputs the result for each addition, along with any errors encountered.

iii) Further Enhancements

You can extend this script to support:

Enhancement Description
Retry Logic Handle transient errors (e.g., throttling) with retry attempts
Add Owners Accept Role column and assign "owner" if needed
Logging Export success/failure logs to a separate CSV
UPN Support Accept UserPrincipalName instead of UserId and resolve it dynamically
License Check Ensure users being added have proper licenses to access Teams


iv) Possible Errors & Solutions

Error Message Cause Fix
Insufficient privileges to complete the operation. Missing delegated permissions Ensure you're using MgGraph -Scopes "TeamMember.ReadWrite.All"
InvalidAuthenticationToken Expired token or session Run Connect-MgGraph again to refresh the authentication token.
BadRequest: Unable to cast object... Improper or missing user@odata.bind format Use the format: "user@odata.bind" "https://graph.microsoft.com/v1.0/users('USER-ID')"
User not found Invalid or deleted UserId in the CSV Use Get-MgUser to verify user exists before import
The specified object is already a member Duplicate add attempt Add a pre-check to skip users already in the team (optional enhancement)

Conclusion

This Graph PowerShell script provides a fast, efficient, and repeatable way to bulk import Microsoft Teams members using a simple CSV file. It's ideal for IT admins looking to streamline onboarding, migrations, or periodic updates to team memberships.

As Microsoft Teams adoption continues to grow, automation tools like this can significantly reduce manual effort and help maintain consistency across your environment.


Graph PowerShell Explorer Widget

20 Graph PowerShell cmdlets with easily accessible "working" examples.


Permission Required

Example:


                


                


                

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