Skip to content

Instantly share code, notes, and snippets.

@MaxMelcher
Created November 7, 2019 09:35
Show Gist options
  • Save MaxMelcher/dd5a40488a9c748e280ab35d02dcff62 to your computer and use it in GitHub Desktop.
Save MaxMelcher/dd5a40488a9c748e280ab35d02dcff62 to your computer and use it in GitHub Desktop.
on demand policy scan
$subscriptionID = “<your-subscription-ID-goes-here>"
# Get AAD Access Token
$azContext = Get-AzContext
$azProfile = [Microsoft.Azure.Commands.Common.Authentication.Abstractions.AzureRmProfileProvider]::Instance.Profile
$profileClient = New-Object -TypeName Microsoft.Azure.Commands.ResourceManager.Common.RMProfileClient -ArgumentList ($azProfile)
$token = $profileClient.AcquireAccessToken($azContext.Subscription.TenantId)
$authHeader = @{
'Authorization'='Bearer ' + $token.AccessToken
}
# Call REST API to trigger policy evaluation on subscription scope
$uri = "https://management.azure.com/subscriptions/$subscriptionId/providers/Microsoft.PolicyInsights/policyStates/latest/triggerEvaluation?api-version=2018-07-01-preview"
$Parameters = @{
Uri = $uri
Method = "Post"
ContentType = "application/json"
Headers = $authHeader
}
Invoke-RestMethod @Parameters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment