Edit

Share via


Get-AzPolicyStateSummary

Gets latest policy compliance states summary for resources.

Syntax

SubscriptionScope (Default)

Get-AzPolicyStateSummary
    [-SubscriptionId <String>]
    [-Top <Int32>]
    [-From <DateTime>]
    [-To <DateTime>]
    [-Filter <String>]
    [-DefaultProfile <IAzureContextContainer>]
    [<CommonParameters>]

ManagementGroupScope

Get-AzPolicyStateSummary
    -ManagementGroupName <String>
    [-Top <Int32>]
    [-From <DateTime>]
    [-To <DateTime>]
    [-Filter <String>]
    [-DefaultProfile <IAzureContextContainer>]
    [<CommonParameters>]

ResourceGroupScope

Get-AzPolicyStateSummary
    -ResourceGroupName <String>
    [-SubscriptionId <String>]
    [-Top <Int32>]
    [-From <DateTime>]
    [-To <DateTime>]
    [-Filter <String>]
    [-DefaultProfile <IAzureContextContainer>]
    [<CommonParameters>]

PolicySetDefinitionScope

Get-AzPolicyStateSummary
    -PolicySetDefinitionName <String>
    [-SubscriptionId <String>]
    [-Top <Int32>]
    [-From <DateTime>]
    [-To <DateTime>]
    [-Filter <String>]
    [-DefaultProfile <IAzureContextContainer>]
    [<CommonParameters>]

PolicyDefinitionScope

Get-AzPolicyStateSummary
    -PolicyDefinitionName <String>
    [-SubscriptionId <String>]
    [-Top <Int32>]
    [-From <DateTime>]
    [-To <DateTime>]
    [-Filter <String>]
    [-DefaultProfile <IAzureContextContainer>]
    [<CommonParameters>]

SubscriptionLevelPolicyAssignmentScope

Get-AzPolicyStateSummary
    -PolicyAssignmentName <String>
    [-SubscriptionId <String>]
    [-Top <Int32>]
    [-From <DateTime>]
    [-To <DateTime>]
    [-Filter <String>]
    [-DefaultProfile <IAzureContextContainer>]
    [<CommonParameters>]

ResourceGroupLevelPolicyAssignmentScope

Get-AzPolicyStateSummary
    -ResourceGroupName <String>
    -PolicyAssignmentName <String>
    [-SubscriptionId <String>]
    [-Top <Int32>]
    [-From <DateTime>]
    [-To <DateTime>]
    [-Filter <String>]
    [-DefaultProfile <IAzureContextContainer>]
    [<CommonParameters>]

ResourceScope

Get-AzPolicyStateSummary
    -ResourceId <String>
    [-Top <Int32>]
    [-From <DateTime>]
    [-To <DateTime>]
    [-Filter <String>]
    [-DefaultProfile <IAzureContextContainer>]
    [<CommonParameters>]

Description

Gets a summary view of latest policy compliance state numbers at various scopes, broken down into policy assignments and policy definitions. It includes only non-compliant policy states.

Examples

Example 1: Get latest non-compliant policy states summary in current subscription scope

Get-AzPolicyStateSummary

Gets the summary view of latest policy compliance states generated in the last day for all resources within the subscription in current session context.

Example 2: Get latest non-compliant policy states summary in the specified subscription scope

Get-AzPolicyStateSummary -SubscriptionId "fff10b27-fff3-fff5-fff8-fffbe01e86a5"

Gets the summary view of latest policy compliance states generated in the last day for all resources within the specified subscription.

Example 3: Get latest non-compliant policy states summary in management group scope

Get-AzPolicyStateSummary -ManagementGroupName "myManagementGroup"

Gets the summary view of latest policy compliance states generated in the last day for all resources within the specified management group.

Example 4: Get latest non-compliant policy states summary in resource group scope in current subscription

Get-AzPolicyStateSummary -ResourceGroupName "myResourceGroup"

Gets the summary view of latest policy compliance states generated in the last day for all resources within the specified resource group (in the subscription in current session context).

Example 5: Get latest non-compliant policy states summary in resource group scope in the specified subscription

Get-AzPolicyStateSummary -SubscriptionId "fff10b27-fff3-fff5-fff8-fffbe01e86a5" -ResourceGroupName "myResourceGroup"

Gets the summary view of latest policy compliance states generated in the last day for all resources within the specified resource group (in the specified subscription).

Example 6: Get latest non-compliant policy states summary for a resource

Get-AzPolicyStateSummary -ResourceId "/subscriptions/fff10b27-fff3-fff5-fff8-fffbe01e86a5/resourceGroups/myResourceGroup/providers/Microsoft.EventHub/namespaces/myns1/eventhubs/eh1/consumergroups/cg1"

Gets the summary view of latest policy compliance states generated in the last day for the specified resource.

Example 7: Get latest non-compliant policy states summary for a policy set definition in current subscription

Get-AzPolicyStateSummary -PolicySetDefinitionName "fff58873-fff8-fff5-fffc-fffbe7c9d697"

Gets the summary view of latest policy compliance states generated in the last day for all resources (within the tenant in current session context) effected by the specified policy set definition (that exists in the subscription in current session context).

Example 8: Get latest non-compliant policy states summary for a policy set definition in the specified subscription

Get-AzPolicyStateSummary -SubscriptionId "fff10b27-fff3-fff5-fff8-fffbe01e86a5" -PolicySetDefinitionName "fff58873-fff8-fff5-fffc-fffbe7c9d697"

Gets the summary view of latest policy compliance states generated in the last day for all resources (within the tenant in current session context) effected by the specified policy set definition (that exists in the specified subscription).

Example 9: Get latest non-compliant policy states summary for a policy definition in current subscription

Get-AzPolicyStateSummary -PolicyDefinitionName "fff58873-fff8-fff5-fffc-fffbe7c9d697"

Gets the summary view of latest policy compliance states generated in the last day for all resources (within the tenant in current session context) effected by the specified policy definition (that exists in the subscription in current session context).

Example 10: Get latest non-compliant policy states summary for a policy definition in the specified subscription

Get-AzPolicyStateSummary -SubscriptionId "fff10b27-fff3-fff5-fff8-fffbe01e86a5" -PolicyDefinitionName "fff58873-fff8-fff5-fffc-fffbe7c9d697"

Gets the summary view of latest policy compliance states generated in the last day for all resources (within the tenant in current session context) effected by the specified policy definition (that exists in the specified subscription).

Example 11: Get latest non-compliant policy states summary for a policy assignment in current subscription

Get-AzPolicyStateSummary -PolicyAssignmentName "ddd8ef92e3714a5ea3d208c1"

Gets the summary view of latest policy compliance states generated in the last day for all resources (within the tenant in current session context) effected by the specified policy assignment (that exists in the subscription in current session context).

Example 12: Get latest non-compliant policy states summary for a policy assignment in the specified subscription

Get-AzPolicyStateSummary -SubscriptionId "fff10b27-fff3-fff5-fff8-fffbe01e86a5" -PolicyAssignmentName "ddd8ef92e3714a5ea3d208c1"

Gets the summary view of latest policy compliance states generated in the last day for all resources (within the tenant in current session context) effected by the specified policy assignment (that exists in the specified subscription).

Example 13: Get latest non-compliant policy states summary for a policy assignment in the specified resource group in the current subscription

Get-AzPolicyStateSummary -ResourceGroupName "myResourceGroup" -PolicyAssignmentName "ddd8ef92e3714a5ea3d208c1"

Gets the summary view of latest policy compliance states generated in the last day for all resources (within the tenant in current session context) effected by the specified policy assignment (that exists in the resource group in the subscription in current session context).

Example 14: Get latest non-compliant policy states summary in current subscription scope, with Top query option

Get-AzPolicyStateSummary -Top 5

Gets the summary view of latest policy compliance states generated in the last day for all resources within the subscription in current session context. The command orders the policy assignment summaries in the results by non-compliant resource counts in descending order, and takes only top 5 of those policy assignment summaries.

Example 15: Get latest non-compliant policy states summary in current subscription scope, with From and To query options

Get-AzPolicyStateSummary -From "2018-03-08 00:00:00Z" -To "2018-03-15 00:00:00Z"

Gets the summary view of latest policy compliance states generated within the date range specified for all resources within the subscription in current session context.

Example 16: Get latest non-compliant policy states summary in current subscription scope, with Filter query option

Get-AzPolicyStateSummary -Filter "(PolicyDefinitionAction eq 'deny' or PolicyDefinitionAction eq 'audit') and ResourceLocation ne 'eastus'"

Gets the summary view of latest policy compliance states generated in the last day for all resources within the subscription in current session context. The command limits the results returned by filtering based on policy definition action (includes deny or audit actions), and resource location (excludes eastus location).

Parameters

-DefaultProfile

The credentials, account, tenant, and subscription used for communication with Azure.

Parameter properties

Type:IAzureContextContainer
Default value:None
Supports wildcards:False
DontShow:False
Aliases:AzContext, AzureRmContext, AzureCredential

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-Filter

Filter expression using OData notation.

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-From

ISO 8601 formatted timestamp specifying the start time of the interval to query. When not specified, defaults to 'To' parameter value minus 1 day.

Parameter properties

Type:DateTime
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-ManagementGroupName

Management group name.

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

ManagementGroupScope
Position:Named
Mandatory:True
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False

-PolicyAssignmentName

Policy assignment name.

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

SubscriptionLevelPolicyAssignmentScope
Position:Named
Mandatory:True
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False
ResourceGroupLevelPolicyAssignmentScope
Position:Named
Mandatory:True
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False

-PolicyDefinitionName

Policy definition name.

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

PolicyDefinitionScope
Position:Named
Mandatory:True
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False

-PolicySetDefinitionName

Policy set definition name.

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

PolicySetDefinitionScope
Position:Named
Mandatory:True
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False

-ResourceGroupName

Resource group name.

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

ResourceGroupScope
Position:Named
Mandatory:True
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False
ResourceGroupLevelPolicyAssignmentScope
Position:Named
Mandatory:True
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False

-ResourceId

Resource ID.

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

ResourceScope
Position:Named
Mandatory:True
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False

-SubscriptionId

Subscription ID.

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

SubscriptionScope
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False
ResourceGroupScope
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False
PolicySetDefinitionScope
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False
PolicyDefinitionScope
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False
SubscriptionLevelPolicyAssignmentScope
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False
ResourceGroupLevelPolicyAssignmentScope
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False

-To

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

Parameter properties

Type:DateTime
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-Top

Maximum number of records to return.

Parameter properties

Type:Int32
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

Inputs

String

Outputs

PolicyStateSummary