When i need quick PowerShell example to make sure i have configured the hosting/infrastructure/egress-allow correctly i use this small example.

To set it up in Azure I go to “app registrations” and click through the defaults for a new registration. I grant it as an app permission. Then i create a secret. You’ll see each of these configuration options in the UI for app registrations (“Certificates and Secrets” and “App Permissions”).

Then, based on this new configuration i create the three environment variables you see below, the first three things used in this small script. The hosting platform will have it’s own approach for environment variable configurations and this is a good way to test that you’ve figured it out.

# Get env variables
$TenantId = (Get-Item -Path Env:TenantId).Value
$ClientId = (Get-Item -Path Env:ClientId).Value
$ClientSecret = (Get-Item -Path Env:ClientSecret).Value

# Request Body for auth
$Body = @{
    'tenant' = $TenantId
    'client_id' = $ClientId
    'scope' = ''
    'client_secret' = $ClientSecret
    'grant_type' = 'client_credentials'

# Auth Params including request body from above. 
$Params = @{
    'Uri' = "$TenantId/oauth2/v2.0/token"
    'Method' = 'Post'
    'Body' = $Body
    'ContentType' = 'application/x-www-form-urlencoded'

$Response = Invoke-RestMethod @Params

$Headers = @{
    'Authorization' = "Bearer $($Response.access_token)"

$Result = Invoke-RestMethod -Uri '' -Headers $Headers

Write-Host $Result.value
Blog Logo

Chad Duffey



Chad Duffey

Blue Team -> Exploit Development & things in-between

Back to Overview