-
Notifications
You must be signed in to change notification settings - Fork 214
/
GraphAPI_utils.ps1
53 lines (45 loc) · 1.51 KB
/
GraphAPI_utils.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
52
# This script contains utility functions for Graph API at https://graph.windows.net
# Office 365 / Azure AD v2, a.k.a. AzureAD module uses this API
# Calls the provisioning SOAP API
function Call-GraphAPI
{
[cmdletbinding()]
Param(
[Parameter(Mandatory=$True)]
[String]$AccessToken,
[Parameter(Mandatory=$True)]
[String]$Command,
[Parameter(Mandatory=$False)]
[String]$ApiVersion="1.61-internal",
[Parameter(Mandatory=$False)]
[ValidateSet('Put','Get','Post','Delete','Patch')]
[String]$Method="Get",
[Parameter(Mandatory=$False)]
$Body,
[Parameter(Mandatory=$False)]
$Headers,
[Parameter(Mandatory=$False)]
[String]$QueryString
)
Process
{
# Set the required variables
$TenantID = (Read-Accesstoken $AccessToken).tid
if($Headers -eq $null)
{
$Headers=@{}
}
$Headers["Authorization"] = "Bearer $AccessToken"
# Call the API
$response = Invoke-RestMethod -UseBasicParsing -Uri "https://graph.windows.net/$TenantId/$Command`?api-version=$ApiVersion$(if(![String]::IsNullOrEmpty($QueryString)){"&$QueryString"})" -ContentType "application/json; charset=utf-8; odata.metadata=none" -Method $Method -Body $Body -Headers $Headers -ErrorAction SilentlyContinue
# Return
if($response.value)
{
return $response.value
}
else
{
return $response
}
}
}