mirror of
https://github.com/Gerenios/AADInternals
synced 2026-06-08 11:09:38 +00:00
59 lines
1.6 KiB
PowerShell
59 lines
1.6 KiB
PowerShell
# 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"
|
|
|
|
if([string]::IsNullOrEmpty($Headers["User-Agent"]))
|
|
{
|
|
$Headers["User-Agent"] = Get-UserAgent
|
|
}
|
|
|
|
# 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
|
|
}
|
|
|
|
}
|
|
}
|
|
|