共用方式為


Get-AzPolicyAssignment

取得原則指派。

語法

Get-AzPolicyAssignment
   [-BackwardCompatible]
   [-DefaultProfile <PSObject>]
   [<CommonParameters>]
Get-AzPolicyAssignment
   -Name <String>
   [-Scope <String>]
   [-BackwardCompatible]
   [-DefaultProfile <PSObject>]
   [<CommonParameters>]
Get-AzPolicyAssignment
   [-Scope <String>]
   -PolicyDefinitionId <String>
   [-BackwardCompatible]
   [-DefaultProfile <PSObject>]
   [<CommonParameters>]
Get-AzPolicyAssignment
   [-Scope <String>]
   [-IncludeDescendent]
   [-BackwardCompatible]
   [-DefaultProfile <PSObject>]
   [<CommonParameters>]
Get-AzPolicyAssignment
   -Scope <String>
   [-BackwardCompatible]
   [-DefaultProfile <PSObject>]
   [<CommonParameters>]
Get-AzPolicyAssignment
   -Id <String>
   [-BackwardCompatible]
   [-DefaultProfile <PSObject>]
   [<CommonParameters>]

Description

Get-AzPolicyAssignment Cmdlet 會取得所有原則指派或特定指派。 識別要依名稱和範圍或標識碼取得的原則指派。

範例

範例 1:取得所有原則指派

Get-AzPolicyAssignment

此命令會取得所有原則指派。

範例 2:取得特定原則指派

$ResourceGroup = Get-AzResourceGroup -Name 'ResourceGroup11'
Get-AzPolicyAssignment -Name 'PolicyAssignment07' -Scope $ResourceGroup.ResourceId

第一個命令會使用 Get-AzResourceGroup Cmdlet 取得名為 ResourceGroup11 的資源群組,並將它儲存在$ResourceGroup變數中。 第二個命令會取得名為 PolicyAssignment07 的原則指派,以取得$ResourceGroup ResourceId 屬性所識別的範圍

範例 3:取得指派給管理群組的所有原則指派

$mgId = 'myManagementGroup'
Get-AzPolicyAssignment -Scope '/providers/Microsoft.Management/managementgroups/$mgId'

第一個命令會指定要查詢的管理群組標識碼。 第二個命令會取得指派給標識符為 『myManagementGroup』 之管理群組的所有原則指派。

範例 4:取得範圍、原則集定義標識碼,以及格式化為清單之所有原則指派的顯示名稱

Get-AzPolicyAssignment | Select-Object -Property Scope, PolicyDefinitionID, DisplayName | Format-List

當您需要尋找 Azure 原則 指派的易讀程式 DisplayName 屬性時,此命令很有用。

範例 5:[Backcompat] 取得範圍、原則集定義標識碼,以及格式化為清單之所有原則指派的顯示名稱

Get-AzPolicyAssignment -BackwardCompatible | Select-Object -ExpandProperty properties | Select-Object -Property Scope, PolicyDefinitionID, DisplayName | Format-List

當您需要尋找 Azure 原則 指派的易讀程式 DisplayName 屬性時,此命令很有用。

參數

-BackwardCompatible

導致 Cmdlet 使用舊版格式將原則特定屬性放在屬性包對象中傳回成品。

類型:SwitchParameter
Position:Named
預設值:None
必要:False
接受管線輸入:False
接受萬用字元:False

-DefaultProfile

DefaultProfile 參數無法運作。 如果針對不同的訂用帳戶執行 Cmdlet,請使用 SubscriptionId 參數。

類型:PSObject
別名:AzureRMContext, AzureCredential
Position:Named
預設值:None
必要:False
接受管線輸入:False
接受萬用字元:False

-Id

要取得的原則指派標識碼。 使用格式 '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'。

類型:String
別名:ResourceId, PolicyAssignmentId
Position:Named
預設值:None
必要:True
接受管線輸入:True
接受萬用字元:False

-IncludeDescendent

取得以指定原則定義 [完整] 標識符為目標的所有原則指派。

類型:SwitchParameter
Position:Named
預設值:None
必要:True
接受管線輸入:True
接受萬用字元:False

-Name

要取得的原則指派名稱。

類型:String
別名:PolicyAssignmentName
Position:Named
預設值:None
必要:True
接受管線輸入:True
接受萬用字元:False

-PolicyDefinitionId

取得以指定原則定義 [完整] 標識符為目標的所有原則指派。

類型:String
Position:Named
預設值:None
必要:True
接受管線輸入:True
接受萬用字元:False

-Scope

原則指派的範圍。 有效範圍包括:管理群組(格式:'/providers/Microsoft.Management/managementGroups/{managementGroup}'),訂用帳戶(格式:'/subscriptions/{subscriptionId}'),資源群組(格式: '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', 或資源 (格式: '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'

類型:String
Position:Named
預設值:None
必要:True
接受管線輸入:True
接受萬用字元:False

輸入

SwitchParameter

String

輸出

IPolicyAssignment