Skip to content

Instantly share code, notes, and snippets.

@cmendible
Created April 8, 2020 11:32
Show Gist options
  • Save cmendible/0aec42881061aaff5fe4f1ea7bf4b66d to your computer and use it in GitHub Desktop.
Save cmendible/0aec42881061aaff5fe4f1ea7bf4b66d to your computer and use it in GitHub Desktop.
On-demand Azure Policy Scan with Azure CLI and Powershell
# Based on @maikvandergaag work: https://msftplayground.com/2019/06/on-demand-azure-policy-scan/
$account = (az account show -o json | ConvertFrom-Json)
$subscriptionId = $account.id
$tenantId = $account.homeTenantId
$token = (az account get-access-token --tenant $tenantId -o json | ConvertFrom-Json).accessToken
$authHeader = @{
'Content-Type'='application/json'
'Authorization'='Bearer ' + $token
}
$restUri = "https://management.azure.com/subscriptions/$subscriptionId/providers/Microsoft.PolicyInsights/policyStates/latest/triggerEvaluation?api-version=2019-10-01"
Invoke-webrequest -Uri $restUri -Method POST -Headers $authHeader -UseBasicParsing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment