Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 9b88b26

Browse files
Add Invoke-ComplianceEvaluation
1 parent 30dd661 commit 9b88b26

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
function Invoke-ComplianceEvaluation {
2+
<#
3+
.SYNOPSIS
4+
Function to trigger compliance evalution for Azure Policies on a specific Resource Group or Subscription
5+
.description
6+
The code assume you are already authenticated to azure
7+
.example
8+
# Load the function
9+
. ./invoke-complianceevaluation
10+
# Trigger Policy Compliance evaluation against current subscription
11+
Invoke-ComplianceEvaluation
12+
.example
13+
# Load the function
14+
. ./invoke-complianceevaluation
15+
# Trigger Policy Compliance evaluation against specified subscription
16+
Invoke-ComplianceEvaluation -subscriptionid <uid>
17+
.example
18+
# Load the function
19+
. ./invoke-complianceevaluation
20+
# Trigger Policy Compliance evaluation against specified resource group in the current subscription
21+
Invoke-ComplianceEvaluation -ResourceGroupName MyRg
22+
23+
.example
24+
# Load the function
25+
. ./invoke-complianceevaluation
26+
# Trigger Policy Compliance evaluation against specified resource group in the specified subscription
27+
Invoke-ComplianceEvaluation -ResourceGroupName MyRg -subscriptionid <uid>
28+
29+
#>
30+
param($resourceGroupName,$subscriptionId)
31+
32+
if(-not $subscriptionId){
33+
$subscriptionId = (Get-AzContext).subscription.id
34+
}
35+
$uri = "https://management.azure.com/subscriptions/$subscriptionId/providers/Microsoft.PolicyInsights/policyStates/latest/triggerEvaluation?api-version=2018年07月01日-preview"
36+
37+
if ($resourceGroupName){
38+
$uri = "https://management.azure.com/subscriptions/$subscriptionId/resourceGroups/$resourceGroupName/providers/Microsoft.PolicyInsights/policyStates/latest/triggerEvaluation?api-version=2018年07月01日-preview"
39+
}
40+
41+
$azContext = Get-AzContext
42+
$azProfile = [Microsoft.Azure.Commands.Common.Authentication.Abstractions.AzureRmProfileProvider]::Instance.Profile
43+
$profileClient = New-Object -TypeName Microsoft.Azure.Commands.ResourceManager.Common.RMProfileClient -ArgumentList ($azProfile)
44+
$token = $profileClient.AcquireAccessToken($azContext.Tenant.Id)
45+
$authHeader = @{
46+
'Content-Type'='application/json'
47+
'Authorization'='Bearer ' + $token.AccessToken
48+
}
49+
Invoke-RestMethod -Method Post -Uri $uri -UseBasicParsing -Headers $authHeader
50+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
```
2+
# The code assume you are already connected to azure
3+
4+
# Load the function
5+
. ./invoke-complianceevaluation
6+
7+
# Trigger Policy Compliance evaluation against current subscription
8+
Invoke-ComplianceEvaluation
9+
10+
# Trigger Policy Compliance evaluation against specified subscription
11+
Invoke-ComplianceEvaluation -subscriptionid <uid>
12+
13+
# Trigger Policy Compliance evaluation against ResourceGroup specified (in current subscription)
14+
Invoke-ComplianceEvaluation -ResourceGroupName MyRg
15+
16+
# Trigger Policy Compliance evaluation against ResourceGroup specified (in specified subscription)
17+
Invoke-ComplianceEvaluation -ResourceGroupName MyRg -subscriptionid <uid>
18+
19+
```

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /