Skip to content

Instantly share code, notes, and snippets.

@pmatthews05
Created June 18, 2020 12:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pmatthews05/a53a189ad845124b3f188098b0e21fe9 to your computer and use it in GitHub Desktop.
Save pmatthews05/a53a189ad845124b3f188098b0e21fe9 to your computer and use it in GitHub Desktop.
#Get a access Token
$tokenResponse = az account get-access-token --resource-type ms-graph | convertFrom-Json
$body = @{
clientId = $($servicePrincipal.objectId)
consentType = "AllPrincipals"
principalId = $null
resourceId = $($APIServicePrincipal.objectId)
scope = "User.Read Directory.ReadWrite.All"
startTime = "0001-01-01T00:00:00Z"
expiryTime = "2299-12-31T00:00:00Z"
}
$apiUrl = "https://graph.microsoft.com/v1.0/oauth2Permissiongrants"
Invoke-RestMethod -Uri $apiUrl -Headers @{Authorization = "Bearer $($tokenResponse.accessToken)" } -Method $method -Body $($body | ConvertTo-Json) -ContentType "application/json"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment