Skip to content

Instantly share code, notes, and snippets.

@JordanTheITGuy
Created May 2, 2023 14:22
Show Gist options
  • Save JordanTheITGuy/2494a48138c64f02937e71765380fad2 to your computer and use it in GitHub Desktop.
Save JordanTheITGuy/2494a48138c64f02937e71765380fad2 to your computer and use it in GitHub Desktop.
Get-AzureAppToken
$tenantId = '' ### Paste your tenant ID here
$appId = '' ### Paste your Application ID here
$appSecret = '' ### Paste your Application secret here
#NOTE: Build the auth response token to the Windows Security Center API (Basically establishing a logged in session)
$resourceAppIdUri = 'https://api.securitycenter.windows.com'
$oAuthUri = "https://login.windows.net/$TenantId/oauth2/token"
$authBody = [Ordered] @{
resource = "$resourceAppIdUri"
client_id = "$appId"
client_secret = "$appSecret"
grant_type = 'client_credentials'
}
$authResponse = Invoke-RestMethod -Method Post -Uri $oAuthUri -Body $authBody -ErrorAction Stop
#NOTE: This returns your access token, and below we pull out the token that will be used as the authorization token going forward.
$token = $authResponse.access_token
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment