forked from Seidlm/Microsoft-Graph-API-Examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Create-Teams.ps1
55 lines (42 loc) · 1.62 KB
/
Create-Teams.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
$clientID = "your ID"
$Clientsecret = "your Secret"
$tenantID = "Your Tenant"
$TeamName="Techguy Team"
$TeamDescription="The official Team for Techguy.at"
$TeamVisibility="public" #public, private
$Owner="[email protected]"
#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 Owner ID
$URLOwnwer = "https://graph.microsoft.com/v1.0/users/$Owner"
$ResultOwner = Invoke-RestMethod -Headers $headers -Uri $URLOwnwer -Method Get
#Create Teams
$BodyJsonTeam = @"
{
"[email protected]":"https://graph.microsoft.com/v1.0/teamsTemplates('standard')",
"displayName":"$TeamName",
"description":"$TeamDescription",
"visibility":"$TeamVisibility",
"members":[
{
"@odata.type":"#microsoft.graph.aadUserConversationMember",
"roles":[
"owner"
],
"[email protected]":"https://graph.microsoft.com/v1.0/users/$($ResultOwner.id)"
}
]
}
"@
$URLTeam = "https://graph.microsoft.com/v1.0/teams"
Invoke-RestMethod -Headers $headers -Uri $URLTeam -Method POST -Body $BodyJsonTeam