In this post, I want to show you how you can add a new Member to a Microsoft Teams Team with PowerShell using MS GRAPH API.
Some of the Use cases❗
✔️Make sure not everyone can add a new Team Member.
✔️Control your Members of a Team outside Teams.
✔️Many more…
API Reference and Permissions
We used the following Docs to get this Script up and running
- Get a user – Microsoft Graph v1.0 | Microsoft Docs
- List all teams in Microsoft Teams for an organization – Microsoft Graph | Microsoft Docs
- Add member to team – Microsoft Graph v1.0 | Microsoft Docs
and I configured the following Permissions
To learn more from Microsoft GRAPH API, see my Blog Series:
Part 1 – Authentication and Azure App – Use Microsoft Graph API with PowerShell – Part 1 » TechGuy
Part 2 – Oauth2.0 – Use Microsoft Graph API with PowerShell – Part 2 » TechGuy
Part 3 – First Powershell Script to get a Teams Lis and Walkthrough – Use Microsoft Graph API with PowerShell – Part 3 » TechGuy
Part 4 – this one – Use Microsoft Graph API with PowerShell – Part 4 » TechGuy
- User.Read.All
- User.ReadWrite.All
- TeamMember.ReadWrite.All
The Script
$clientID = "your ID"
$Clientsecret = "your Secret"
$tenantID = "Your Tenant"
$TeamName="Marketing"
$Member="michael@techguy.at"
#Connect to GRAPH API
$tokenBody = @{
Grant_Type = "client_credentials"
Scope = "https://graph.microsoft.com/.default"
Client_Id = $clientId
Client_Secret = $clientSecret
}
$tokenResponse = Invoke-RestMethod -Uri "https://login.microsoftonline.com/$tenantID/oauth2/v2.0/token" -Method POST -Body $tokenBody
$headers = @{
"Authorization" = "Bearer $($tokenResponse.access_token)"
"Content-type" = "application/json"
}
#Get Member ID
$URLMember = "https://graph.microsoft.com/v1.0/users/$Member"
$ResultMember = Invoke-RestMethod -Headers $headers -Uri $URLMember -Method Get
#Get Team ID
$URLTeam = "https://graph.microsoft.com/v1.0//groups?$filter=resourceProvisioningOptions/Any(x:x eq 'Team')"
$ResultTeam=(Invoke-RestMethod -Headers $headers -Uri $URLTeam -Method Get).value | Where-Object -Property displayName -Value $TeamName -eq
#Add User
$URL = "https://graph.microsoft.com/v1.0/groups/$($ResultTeam.id)/members/`$ref"
$body = [ordered]@{
"@odata.id" = "https://graph.microsoft.com/v1.0/users/$($ResultMember.id)"
}
$bodyJSON = $body | ConvertTo-Json
Invoke-RestMethod -Headers $headers -Uri $URL -Method POST -Body $bodyJSON
GitHub Repo
Here you can find the GitHub Repo with a lot of other examples: Seidlm/Microsoft-Teams (github.com) and Seidlm/Microsoft-Graph-API-Examples (github.com)
Delegate adding Team Members as Self Service with au2mator
With au2mator Self Service Portal, you can create a Service and delegate the task to add new Members to a Microsoft Teams Team.

Some of the Use cases❗
✔️Make sure not everyone can add new Team Members.
✔️Control your Members of a Team outside Teams.
✔️Many more…
More Details: www.au2mator.com
Michael Seidl aka Techguy
au2mate everything
Hi, I’m having a problem with using this line of code: $URL = “https://graph.microsoft.com/v1.0/groups/$($ResultTeam.id)/members/`$ref”
I can’t figure out where $ref on the end of the line is coming from…
Also in the line above is a strange thing ending on -eq
Is this normal?
Thanks
Hi, would recommend getting the Code from GitHub Repo, to prevent wrong Characters when you copy the Code from the Blog
the “$ref” is just the URL, this is not a PowerShell Variable
Sometimes it can happen that you do not need the ` before the $ Sign.