Azure policy: How to trigger evaluation manually

Matteo 101 Reputation points
2020-06-18T08:01:37.363+00:00

Dear all,
other than waiting 24hrs or make a little resource change that would trigger it within 15 minutes, do we have any way to trigger already applied policies evaluation?

This methodology that was working before now seems to be ignored.

$subscriptionId = "SubscriptionID"
$uri = "https://management.azure.com/subscriptions/$subscriptionId/providers/Microsoft.PolicyInsights/policyStates/latest/triggerEvaluation?api-version=2018-07-01-preview"
$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.Tenant.Id)
$authHeader = @{
    'Content-Type'='application/json'
    'Authorization'='Bearer ' + $token.AccessToken
}
Invoke-RestMethod -Method Post -Uri $uri -UseBasicParsing -Headers $authHeader -Debug

Any advice on it would be great.

Azure Policy
Azure Policy
An Azure service that is used to implement corporate governance and standards at scale for Azure resources.
1,018 questions
{count} votes

Accepted answer
  1. Matteo 101 Reputation points
    2020-06-18T08:08:34.697+00:00

    Sorry about that,
    my fault, it still works.

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Shannmuka Buddabathini 0 Reputation points
    2023-02-04T06:44:14.4133333+00:00

    I think this Azure CLI command "az policy state trigger-scan" should also work.
    Source: https://www.danielstechblog.io/trigger-an-on-demand-azure-policy-compliance-evaluation-scan/

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.