Created
April 8, 2020 11:32
-
-
Save cmendible/0aec42881061aaff5fe4f1ea7bf4b66d to your computer and use it in GitHub Desktop.
On-demand Azure Policy Scan with Azure CLI and Powershell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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