Skip to content

Commit f8311af

Browse files
Merge pull request #115162 from DCtheGeek/dmc-policy-psscan
Add PS for on-demand scan
2 parents e63c00e + 045c02a commit f8311af

File tree

1 file changed

+54
-10
lines changed

1 file changed

+54
-10
lines changed

articles/governance/policy/how-to/get-compliance-data.md

Lines changed: 54 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Get policy compliance data
33
description: Azure Policy evaluations and effects determine compliance. Learn how to get the compliance details of your Azure resources.
4-
ms.date: 02/01/2019
4+
ms.date: 05/20/2020
55
ms.topic: how-to
66
---
77
# Get compliance data of Azure resources
@@ -63,10 +63,54 @@ Evaluations of assigned policies and initiatives happen as the result of various
6363

6464
### On-demand evaluation scan
6565

66-
An evaluation scan for a subscription or a resource group can be started with a call to the REST
67-
API. This scan is an asynchronous process. As such, the REST endpoint to start the scan doesn't wait
68-
until the scan is complete to respond. Instead, it provides a URI to query the status of the
69-
requested evaluation.
66+
An evaluation scan for a subscription or a resource group can be started with Azure PowerShell or a
67+
call to the REST API. This scan is an asynchronous process.
68+
69+
#### On-demand evaluation scan - Azure PowerShell
70+
71+
The compliance scan is started with the
72+
[Start-AzPolicyComplianceScan](/powershell/module/az.policyinsights/start-azpolicycompliancescan)
73+
cmdlet.
74+
75+
By default, `Start-AzPolicyComplianceScan` starts an evaluation for all resources in the current
76+
subscription. To start an evaluation on a specific resource group, use the **ResourceGroupName**
77+
parameter. The following example starts a compliance scan in the current subscription for the _MyRG_
78+
resource group:
79+
80+
```azurepowershell-interactive
81+
Start-AzPolicyComplianceScan -ResourceGroupName MyRG
82+
```
83+
84+
You can have PowerShell wait for the asynchronous call to complete before providing the results
85+
output or have it run in the background as a
86+
[job](/powershell/module/microsoft.powershell.core/about/about_jobs). To use a PowerShell job to run
87+
the compliance scan in the background, use the **AsJob** parameter and set the value to an object,
88+
such as `$job` in this example:
89+
90+
```azurepowershell-interactive
91+
$job = Start-AzPolicyComplianceScan -AsJob
92+
```
93+
94+
You can check on the status of the job by checking on the `$job` object. The job is of the type
95+
`Microsoft.Azure.Commands.Common.AzureLongRunningJob`. Use `Get-Member` on the `$job` object to see
96+
available properties and methods.
97+
98+
While the compliance scan is running, checking the `$job` object outputs results such as these:
99+
100+
```azurepowershell-interactive
101+
$job
102+
103+
Id Name PSJobTypeName State HasMoreData Location Command
104+
-- ---- ------------- ----- ----------- -------- -------
105+
2 Long Running O… AzureLongRunni… Running True localhost Start-AzPolicyCompliance…
106+
```
107+
108+
When the compliance scan completes, the **State** property changes to _Completed_.
109+
110+
#### On-demand evaluation scan - REST
111+
112+
As an asynchronous process, the REST endpoint to start the scan doesn't wait until the scan is
113+
complete to respond. Instead, it provides a URI to query the status of the requested evaluation.
70114

71115
In each REST API URI, there are variables that are used that you need to replace with your own values:
72116

@@ -79,20 +123,20 @@ scope with a REST API **POST** command using the following URI structures:
79123
- Subscription
80124

81125
```http
82-
POST https://management.azure.com/subscriptions/{subscriptionId}/providers/Microsoft.PolicyInsights/policyStates/latest/triggerEvaluation?api-version=2018-07-01-preview
126+
POST https://management.azure.com/subscriptions/{subscriptionId}/providers/Microsoft.PolicyInsights/policyStates/latest/triggerEvaluation?api-version=2019-10-01
83127
```
84128

85129
- Resource group
86130

87131
```http
88-
POST https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{YourRG}/providers/Microsoft.PolicyInsights/policyStates/latest/triggerEvaluation?api-version=2018-07-01-preview
132+
POST https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{YourRG}/providers/Microsoft.PolicyInsights/policyStates/latest/triggerEvaluation?api-version=2019-10-01
89133
```
90134

91135
The call returns a **202 Accepted** status. Included in the response header is a **Location**
92136
property with the following format:
93137

94138
```http
95-
https://management.azure.com/subscriptions/{subscriptionId}/providers/Microsoft.PolicyInsights/asyncOperationResults/{ResourceContainerGUID}?api-version=2018-07-01-preview
139+
https://management.azure.com/subscriptions/{subscriptionId}/providers/Microsoft.PolicyInsights/asyncOperationResults/{ResourceContainerGUID}?api-version=2019-10-01
96140
```
97141

98142
`{ResourceContainerGUID}` is statically generated for the scope requested. If a scope is already
@@ -203,8 +247,8 @@ additional context and information about those events.
203247

204248
### Understand non-compliance
205249

206-
When a resources is determined to be **non-compliant**, there are many possible reasons. To
207-
determine the reason a resource is **non-compliant** or to find the change responsible, see
250+
When a resource is determined to be **non-compliant**, there are many possible reasons. To determine
251+
the reason a resource is **non-compliant** or to find the change responsible, see
208252
[Determine non-compliance](./determine-non-compliance.md).
209253

210254
## Command line

0 commit comments

Comments
 (0)