Skip to content

Instantly share code, notes, and snippets.

@gsscoder
Created December 30, 2020 10:55
Show Gist options
  • Select an option

  • Save gsscoder/d07b070b7acd2800c1d51a8d064e92b2 to your computer and use it in GitHub Desktop.

Select an option

Save gsscoder/d07b070b7acd2800c1d51a8d064e92b2 to your computer and use it in GitHub Desktop.
PowerShell code to get the bearer token using an app registration
$tenantId = 'your_tenant_id'
$clientId = 'your_client_id'
$clientSecret = 'your_client_secret'
$tokenResponse = (Invoke-WebRequest -Uri "https://login.microsoftonline.com/$tenantId/oauth2/token" `
-Method Post -UseBasicParsing `
-Body "grant_type=client_credentials&client_id=$clientId&client_secret=$clientSecret").Content
"$(($tokenResponse | ConvertFrom-Json).access_token)`n" | Write-Host
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment