Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Create new Teams team
[Parameter (Mandatory= $true)]
[String] $teamname,
[Parameter (Mandatory= $true)]
[String] $owner
# Azure AD OAuth Application Token for Graph API
# Get OAuth token for a AAD Application (returned as $token)
# Application (client) ID, tenant ID and secret
#Application (client) ID, tenant ID and secret
$clientId = "623a6fcb-1980-440d-818b-bc851b773919"
$tenantId = "29594fb0-53f2-490c-a1be-8b2cca824805"
$clientSecret = Get-AutomationVariable -Name 'clientsecret'
# Contruct URI
$uri = "$tenantId/oauth2/v2.0/token"
# Construct Body
$body1 = @{
client_id = $clientId
scope = ""
client_secret = $clientSecret
grant_type = "client_credentials"
# Get OAuth 2.0 Token
$tokenRequest = Invoke-WebRequest -Method Post -Uri $uri -ContentType "application/x-www-form-urlencoded" -Body $body1 -UseBasicParsing
$token = ($tokenRequest.Content | ConvertFrom-Json).access_token
#Get ID of team requester and set as owner.
$uri = ''+"$owner"+'?$select=id'
$method = "GET"
$query = Invoke-WebRequest -Method $method -Uri $uri -ContentType "application/json" -Headers @{Authorization = "Bearer $token"} -ErrorAction Stop -UseBasicParsing
$ownerID = ($query.content | ConvertFrom-Json).id
# Specify the URI to call and method
$uri = ""
$method = "POST"
$body = @"
"template@odata.bind": "",
"displayName": "$teamname",
"description": "My Sample Team’s Description",
"owners@odata.bind": [
# Run Graph API query
$query = Invoke-WebRequest -Method $method -Uri $uri -ContentType "application/json" -Body $body -Headers @{Authorization = "Bearer $token"} -ErrorAction Stop -UseBasicParsing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment