Partilhar via


Policy States - List Query Results For Resource Group

Queries policy states for the resources under the resource group.

POST https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesResource}/queryResults?api-version=2019-10-01
POST https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.PolicyInsights/policyStates/{policyStatesResource}/queryResults?api-version=2019-10-01&$top={$top}&$orderby={$orderby}&$select={$select}&$from={$from}&$to={$to}&$filter={$filter}&$apply={$apply}&$skiptoken={$skiptoken}

URI Parameters

Name In Required Type Description
policyStatesResource
path True

PolicyStatesResource

The virtual resource under PolicyStates resource type. In a given time range, 'latest' represents the latest policy state(s), whereas 'default' represents all policy state(s).

resourceGroupName
path True

string

Resource group name.

subscriptionId
path True

string

Microsoft Azure subscription ID.

api-version
query True

string

Client Api Version.

$apply
query

string

OData apply expression for aggregations.

$filter
query

string

OData filter expression.

$from
query

string

date-time

ISO 8601 formatted timestamp specifying the start time of the interval to query. When not specified, the service uses ($to - 1-day).

$orderby
query

string

Ordering expression using OData notation. One or more comma-separated column names with an optional "desc" (the default) or "asc", e.g. "$orderby=PolicyAssignmentId, ResourceId asc".

$select
query

string

Select expression using OData notation. Limits the columns on each record to just those requested, e.g. "$select=PolicyAssignmentId, ResourceId".

$skiptoken
query

string

Skiptoken is only provided if a previous response returned a partial result as a part of nextLink element.

$to
query

string

date-time

ISO 8601 formatted timestamp specifying the end time of the interval to query. When not specified, the service uses request time.

$top
query

integer

int32

Maximum number of records to return.

Responses

Name Type Description
200 OK

PolicyStatesQueryResults

Query results.

Other Status Codes

QueryFailure

Error response describing why the operation failed.

Security

azure_auth

Azure Active Directory OAuth2 Flow

Type: oauth2
Flow: implicit
Authorization URL: https://login.microsoftonline.com/common/oauth2/authorize

Scopes

Name Description
user_impersonation impersonate your user account

Examples

Query latest at resource group scope
Query latest at resource group scope with next link

Query latest at resource group scope

Sample request

POST https://management.azure.com/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/resourceGroups/myResourceGroup/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2019-10-01

Sample response

{
  "@odata.nextLink": null,
  "@odata.context": "https://management.azure.com/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/resourcegroups/myResourceGroup/providers/Microsoft.PolicyInsights/policyStates/$metadata#latest",
  "@odata.count": 2,
  "value": [
    {
      "@odata.id": null,
      "@odata.context": "https://management.azure.com/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/resourcegroups/myResourceGroup/providers/Microsoft.PolicyInsights/policyStates/$metadata#latest/$entity",
      "timestamp": "2019-10-09T18:42:42Z",
      "resourceId": "/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/resourceGroups/myResourceGroup/providers/Microsoft.Storage/storageAccounts/mysa1",
      "policyAssignmentId": "/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/providers/Microsoft.Authorization/policyAssignments/3f3c4330183b4e218fe6fd29",
      "policyDefinitionId": "/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/providers/Microsoft.Authorization/policyDefinitions/24813039-7534-408a-9842-eb99f45721b1",
      "effectiveParameters": null,
      "isCompliant": false,
      "subscriptionId": "fffedd8f-ffff-fffd-fffd-fffed2f84852",
      "resourceType": "/Microsoft.Storage/storageAccounts",
      "resourceLocation": "eastus",
      "resourceGroup": "myResourceGroup",
      "resourceTags": "tbd",
      "policyAssignmentName": "3f3c4330183b4e218fe6fd29",
      "policyAssignmentOwner": "tbd",
      "policyAssignmentParameters": "{}",
      "policyAssignmentScope": "/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852",
      "policyDefinitionName": "24813039-7534-408a-9842-eb99f45721b1",
      "policyDefinitionAction": "audit",
      "policyDefinitionCategory": "tbd",
      "policySetDefinitionId": "/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/providers/Microsoft.Authorization/policySetDefinitions/3e3807c1-65c9-49e0-a406-82d8ae3e338c",
      "policySetDefinitionName": "3e3807c1-65c9-49e0-a406-82d8ae3e338c",
      "policySetDefinitionOwner": null,
      "policySetDefinitionCategory": null,
      "policySetDefinitionParameters": null,
      "managementGroupIds": "mymg,fff988bf-fff1-ffff-fffb-fffcd011db47",
      "policyDefinitionReferenceId": null,
      "complianceState": "NonCompliant",
      "policyDefinitionGroupNames": [
        "myGroup"
      ],
      "policyDefinitionVersion": "1.0.0-preview",
      "policySetDefinitionVersion": "2.0.1",
      "policyAssignmentVersion": "1.0.0"
    },
    {
      "@odata.id": null,
      "@odata.context": "https://management.azure.com/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/resourcegroups/myResourceGroup/providers/Microsoft.PolicyInsights/policyStates/$metadata#latest/$entity",
      "timestamp": "2019-10-09T18:42:42Z",
      "resourceId": "/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/resourceGroups/myResourceGroup/providers/Microsoft.Storage/storageAccounts/mysa1",
      "policyAssignmentId": "/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/providers/Microsoft.Authorization/policyAssignments/3f3c4330183b4e218fe6fd29",
      "policyDefinitionId": "/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/providers/Microsoft.Authorization/policyDefinitions/3e3807c1-65c9-49e0-a406-82d8ae3e3682",
      "effectiveParameters": null,
      "isCompliant": true,
      "subscriptionId": "fffedd8f-ffff-fffd-fffd-fffed2f84852",
      "resourceType": "/Microsoft.Storage/storageAccounts",
      "resourceLocation": "eastus",
      "resourceGroup": "myResourceGroup",
      "resourceTags": "tbd",
      "policyAssignmentName": "3f3c4330183b4e218fe6fd29",
      "policyAssignmentOwner": "tbd",
      "policyAssignmentParameters": "{}",
      "policyAssignmentScope": "/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852",
      "policyDefinitionName": "3e3807c1-65c9-49e0-a406-82d8ae3e3682",
      "policyDefinitionAction": "audit",
      "policyDefinitionCategory": "tbd",
      "policySetDefinitionId": "/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/providers/Microsoft.Authorization/policySetDefinitions/3e3807c1-65c9-49e0-a406-82d8ae3e338c",
      "policySetDefinitionName": "3e3807c1-65c9-49e0-a406-82d8ae3e338c",
      "policySetDefinitionOwner": null,
      "policySetDefinitionCategory": null,
      "policySetDefinitionParameters": null,
      "managementGroupIds": "mymg,fff988bf-fff1-ffff-fffb-fffcd011db47",
      "policyDefinitionReferenceId": null,
      "complianceState": "Compliant",
      "policyDefinitionGroupNames": [
        "myGroup"
      ],
      "policyDefinitionVersion": "1.0.0-preview",
      "policySetDefinitionVersion": "2.0.1",
      "policyAssignmentVersion": "1.0.0"
    }
  ]
}

Sample request

POST https://management.azure.com/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/resourceGroups/myResourceGroup/providers/Microsoft.PolicyInsights/policyStates/latest/queryResults?api-version=2019-10-01&$skiptoken=WpmWfBSvPhkAK6QD

Sample response

{
  "@odata.nextLink": null,
  "@odata.context": "https://management.azure.com/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/resourcegroups/myResourceGroup/providers/Microsoft.PolicyInsights/policyStates/$metadata#latest",
  "@odata.count": 2,
  "value": [
    {
      "@odata.id": null,
      "@odata.context": "https://management.azure.com/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/resourcegroups/myResourceGroup/providers/Microsoft.PolicyInsights/policyStates/$metadata#latest/$entity",
      "timestamp": "2019-10-09T18:42:42Z",
      "resourceId": "/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/resourceGroups/myResourceGroup/providers/Microsoft.Storage/storageAccounts/mysa1",
      "policyAssignmentId": "/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/providers/Microsoft.Authorization/policyAssignments/3f3c4330183b4e218fe6fd29",
      "policyDefinitionId": "/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/providers/Microsoft.Authorization/policyDefinitions/24813039-7534-408a-9842-eb99f45721b1",
      "effectiveParameters": null,
      "isCompliant": false,
      "subscriptionId": "fffedd8f-ffff-fffd-fffd-fffed2f84852",
      "resourceType": "/Microsoft.Storage/storageAccounts",
      "resourceLocation": "eastus",
      "resourceGroup": "myResourceGroup",
      "resourceTags": "tbd",
      "policyAssignmentName": "3f3c4330183b4e218fe6fd29",
      "policyAssignmentOwner": "tbd",
      "policyAssignmentParameters": "{}",
      "policyAssignmentScope": "/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852",
      "policyDefinitionName": "24813039-7534-408a-9842-eb99f45721b1",
      "policyDefinitionAction": "audit",
      "policyDefinitionCategory": "tbd",
      "policySetDefinitionId": "/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/providers/Microsoft.Authorization/policySetDefinitions/3e3807c1-65c9-49e0-a406-82d8ae3e338c",
      "policySetDefinitionName": "3e3807c1-65c9-49e0-a406-82d8ae3e338c",
      "policySetDefinitionOwner": null,
      "policySetDefinitionCategory": null,
      "policySetDefinitionParameters": null,
      "managementGroupIds": "mymg,fff988bf-fff1-ffff-fffb-fffcd011db47",
      "policyDefinitionReferenceId": null,
      "complianceState": "NonCompliant",
      "policyDefinitionGroupNames": [
        "myGroup"
      ]
    },
    {
      "@odata.id": null,
      "@odata.context": "https://management.azure.com/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/resourcegroups/myResourceGroup/providers/Microsoft.PolicyInsights/policyStates/$metadata#latest/$entity",
      "timestamp": "2019-10-09T18:42:42Z",
      "resourceId": "/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/resourceGroups/myResourceGroup/providers/Microsoft.Storage/storageAccounts/mysa1",
      "policyAssignmentId": "/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/providers/Microsoft.Authorization/policyAssignments/3f3c4330183b4e218fe6fd29",
      "policyDefinitionId": "/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/providers/Microsoft.Authorization/policyDefinitions/3e3807c1-65c9-49e0-a406-82d8ae3e3682",
      "effectiveParameters": null,
      "isCompliant": true,
      "subscriptionId": "fffedd8f-ffff-fffd-fffd-fffed2f84852",
      "resourceType": "/Microsoft.Storage/storageAccounts",
      "resourceLocation": "eastus",
      "resourceGroup": "myResourceGroup",
      "resourceTags": "tbd",
      "policyAssignmentName": "3f3c4330183b4e218fe6fd29",
      "policyAssignmentOwner": "tbd",
      "policyAssignmentParameters": "{}",
      "policyAssignmentScope": "/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852",
      "policyDefinitionName": "3e3807c1-65c9-49e0-a406-82d8ae3e3682",
      "policyDefinitionAction": "audit",
      "policyDefinitionCategory": "tbd",
      "policySetDefinitionId": "/subscriptions/fffedd8f-ffff-fffd-fffd-fffed2f84852/providers/Microsoft.Authorization/policySetDefinitions/3e3807c1-65c9-49e0-a406-82d8ae3e338c",
      "policySetDefinitionName": "3e3807c1-65c9-49e0-a406-82d8ae3e338c",
      "policySetDefinitionOwner": null,
      "policySetDefinitionCategory": null,
      "policySetDefinitionParameters": null,
      "managementGroupIds": "mymg,fff988bf-fff1-ffff-fffb-fffcd011db47",
      "policyDefinitionReferenceId": null,
      "complianceState": "Compliant",
      "policyDefinitionGroupNames": [
        "myGroup"
      ]
    }
  ]
}

Definitions

Name Description
ComponentStateDetails

Component state details.

Error

Error definition.

ExpressionEvaluationDetails

Evaluation details of policy language expressions.

IfNotExistsEvaluationDetails

Evaluation details of IfNotExists effect.

PolicyEvaluationDetails

Policy evaluation details.

PolicyState

Policy state record.

PolicyStatesQueryResults

Query results.

PolicyStatesResource

The virtual resource under PolicyStates resource type. In a given time range, 'latest' represents the latest policy state(s), whereas 'default' represents all policy state(s).

QueryFailure

Error response.

ComponentStateDetails

Component state details.

Name Type Description
complianceState

string

Component compliance state.

id

string

Component Id.

name

string

Component name.

timestamp

string

Component compliance evaluation timestamp.

type

string

Component type.

Error

Error definition.

Name Type Description
code

string

Service specific error code which serves as the substatus for the HTTP error code.

message

string

Description of the error.

ExpressionEvaluationDetails

Evaluation details of policy language expressions.

Name Type Description
expression

string

Expression evaluated.

expressionKind

string

The kind of expression that was evaluated.

expressionValue

object

Value of the expression.

operator

string

Operator to compare the expression value and the target value.

path

string

Property path if the expression is a field or an alias.

result

string

Evaluation result.

targetValue

object

Target value to be compared with the expression value.

IfNotExistsEvaluationDetails

Evaluation details of IfNotExists effect.

Name Type Description
resourceId

string

ID of the last evaluated resource for IfNotExists effect.

totalResources

integer

Total number of resources to which the existence condition is applicable.

PolicyEvaluationDetails

Policy evaluation details.

Name Type Description
evaluatedExpressions

ExpressionEvaluationDetails[]

Details of the evaluated expressions.

ifNotExistsDetails

IfNotExistsEvaluationDetails

Evaluation details of IfNotExists effect.

PolicyState

Policy state record.

Name Type Description
@odata.context

string

OData context string; used by OData clients to resolve type information based on metadata.

@odata.id

string

OData entity ID; always set to null since policy state records do not have an entity ID.

complianceState

string

Compliance state of the resource.

components

ComponentStateDetails[]

Components state compliance records populated only when URL contains $expand=components clause.

effectiveParameters

string

Effective parameters for the policy assignment.

isCompliant

boolean

Flag which states whether the resource is compliant against the policy assignment it was evaluated against. This property is deprecated; please use ComplianceState instead.

managementGroupIds

string

Comma separated list of management group IDs, which represent the hierarchy of the management groups the resource is under.

policyAssignmentId

string

Policy assignment ID.

policyAssignmentName

string

Policy assignment name.

policyAssignmentOwner

string

Policy assignment owner.

policyAssignmentParameters

string

Policy assignment parameters.

policyAssignmentScope

string

Policy assignment scope.

policyAssignmentVersion

string

Evaluated policy assignment version.

policyDefinitionAction

string

Policy definition action, i.e. effect.

policyDefinitionCategory

string

Policy definition category.

policyDefinitionGroupNames

string[]

Policy definition group names.

policyDefinitionId

string

Policy definition ID.

policyDefinitionName

string

Policy definition name.

policyDefinitionReferenceId

string

Reference ID for the policy definition inside the policy set, if the policy assignment is for a policy set.

policyDefinitionVersion

string

Evaluated policy definition version.

policyEvaluationDetails

PolicyEvaluationDetails

Policy evaluation details.

policySetDefinitionCategory

string

Policy set definition category, if the policy assignment is for a policy set.

policySetDefinitionId

string

Policy set definition ID, if the policy assignment is for a policy set.

policySetDefinitionName

string

Policy set definition name, if the policy assignment is for a policy set.

policySetDefinitionOwner

string

Policy set definition owner, if the policy assignment is for a policy set.

policySetDefinitionParameters

string

Policy set definition parameters, if the policy assignment is for a policy set.

policySetDefinitionVersion

string

Evaluated policy set definition version.

resourceGroup

string

Resource group name.

resourceId

string

Resource ID.

resourceLocation

string

Resource location.

resourceTags

string

List of resource tags.

resourceType

string

Resource type.

subscriptionId

string

Subscription ID.

timestamp

string

Timestamp for the policy state record.

PolicyStatesQueryResults

Query results.

Name Type Description
@odata.context

string

OData context string; used by OData clients to resolve type information based on metadata.

@odata.count

integer

OData entity count; represents the number of policy state records returned.

@odata.nextLink

string

Odata next link; URL to get the next set of results.

value

PolicyState[]

Query results.

PolicyStatesResource

The virtual resource under PolicyStates resource type. In a given time range, 'latest' represents the latest policy state(s), whereas 'default' represents all policy state(s).

Name Type Description
default

string

latest

string

QueryFailure

Error response.

Name Type Description
error

Error

Error definition.