共用方式為


az policy definition

管理原則定義。

原則定義是指定允許或不允許的 Azure 資源設定的規則。

命令

名稱 Description 類型 狀態
az policy definition create

建立原則定義。

Core GA
az policy definition delete

刪除原則定義。

Core GA
az policy definition list

擷取原則定義。

Core GA
az policy definition show

擷取原則定義。

Core GA
az policy definition update

更新原則定義。

Core GA

az policy definition create

建立原則定義。

在指定的訂用帳戶或管理群組中建立原則定義,其中包含指定的名稱和其他屬性。

az policy definition create --name
                            [--description]
                            [--display-name]
                            [--management-group]
                            [--metadata]
                            [--mode]
                            [--params]
                            [--rule --rules]
                            [--version]

範例

建立唯讀儲存原則

az policy definition create --name readOnlyStorage --rules "{ 'if': { 'field': 'type', 'equals': 'Microsoft.Storage/storageAccounts/write' }, 'then': { 'effect': 'deny' } }"

使用參數建立原則定義

az policy definition create --name allowedLocations --rules "{ 'if': { 'allOf': [{ 'field': 'location','notIn': '[parameters(\'listOfAllowedLocations\')]' }, { 'field': 'location', 'notEquals': 'global' }, { 'field': 'type', 'notEquals': 'Microsoft.AzureActiveDirectory/b2cDirectories'}] }, 'then': { 'effect': 'deny' } }" --params "{ 'allowedLocations': {'type': 'array', 'metadata': { 'description': 'The list of locations that can be specified when deploying resources', 'strongType': 'location', 'displayName': 'Allowed locations' } } }"

建立可在管理群組內套用的唯讀儲存體原則

az policy definition create -n readOnlyStorage --management-group "MyManagementGroup" --rules "{ 'if': { 'field': 'type', 'equals': 'Microsoft.Storage/storageAccounts/write' }, 'then': { 'effect': 'deny' } }"

使用 mode 建立原則定義

az policy definition create --name TagsPolicyDefinition --subscription "MySubscription" --mode Indexed --rules "{ 'if': { 'field': 'tags', 'exists': 'false' }, 'then': { 'effect': 'deny' } }"

必要參數

--name -n

原則定義的名稱。

選擇性參數

下列參數是選擇性參數,但視內容而定,命令可能需要一或多個參數才能成功執行。

--description

原則定義描述。

屬性
參數群組: Properties Arguments
--display-name

原則定義的顯示名稱。

屬性
參數群組: Properties Arguments
--management-group

管理小組。

--metadata

原則定義中繼資料。 支援速記語法、json-file 和 yaml-file。 請嘗試 “??” 以顯示更多。

屬性
參數群組: Properties Arguments
--mode -m

原則定義模式。

屬性
參數群組: Properties Arguments
預設值: Indexed
--params -p

原則規則參數定義。 支援速記語法、json-file 和 yaml-file。 請嘗試 “??” 以顯示更多。

屬性
參數群組: Properties Arguments
--rule --rules

政策規則。 支援速記語法、json-file 和 yaml-file。 請嘗試 “??” 以顯示更多。

屬性
參數群組: Properties Arguments
--version

原則定義版本。

屬性
參數群組: Properties Arguments
全域參數
--debug

提高日誌詳細程度以顯示所有調試日誌。

屬性
預設值: False
--help -h

顯示此說明訊息並結束。

--only-show-errors

只顯示錯誤,隱藏警告。

屬性
預設值: False
--output -o

輸出格式。

屬性
預設值: json
接受的值: json, jsonc, none, table, tsv, yaml, yamlc
--query

JMESPath 查詢字串。 如需詳細資訊和範例,請參閱 http://jmespath.org/

--subscription

訂用帳戶的名稱或識別碼。 您可以使用 az account set -s NAME_OR_ID 設定預設訂用帳戶。

--verbose

增加記錄的詳細程度。 針對完整偵錯記錄使用 --debug。

屬性
預設值: False

az policy definition delete

重大變更

在資源命令的未來版本中,行為將會變更。 略過確認提示需要提供 -y 參數。

刪除原則定義。

刪除指定訂用帳戶或管理群組中具有指定名稱和其他屬性的原則定義。

az policy definition delete --name
                            [--management-group]

範例

刪除原則定義

az policy definition delete --name MyPolicyDefinition

必要參數

--name -n

原則定義的名稱。

選擇性參數

下列參數是選擇性參數,但視內容而定,命令可能需要一或多個參數才能成功執行。

--management-group

管理小組。

全域參數
--debug

提高日誌詳細程度以顯示所有調試日誌。

屬性
預設值: False
--help -h

顯示此說明訊息並結束。

--only-show-errors

只顯示錯誤,隱藏警告。

屬性
預設值: False
--output -o

輸出格式。

屬性
預設值: json
接受的值: json, jsonc, none, table, tsv, yaml, yamlc
--query

JMESPath 查詢字串。 如需詳細資訊和範例,請參閱 http://jmespath.org/

--subscription

訂用帳戶的名稱或識別碼。 您可以使用 az account set -s NAME_OR_ID 設定預設訂用帳戶。

--verbose

增加記錄的詳細程度。 針對完整偵錯記錄使用 --debug。

屬性
預設值: False

az policy definition list

擷取原則定義。

擷取指定訂用帳戶或管理群組中所有原則定義的清單。

az policy definition list [--filter]
                          [--management-group]
                          [--max-items]
                          [--next-token]

範例

列出內建原則定義

az policy definition list --filter atScopeAndBelow()

依管理群組列出原則定義

az policy definition list --management-group MyManagementGroup

依訂用帳戶列出原則定義

az policy definition list

選擇性參數

下列參數是選擇性參數,但視內容而定,命令可能需要一或多個參數才能成功執行。

--filter

篩選清單結果。

--management-group

管理小組。

--max-items

命令輸出中要傳回的項目總數。 如果可用的專案總數超過指定的值,則會在命令的輸出中提供令牌。 若要繼續分頁,請在後續命令的 --next-token 自變數中提供令牌值。

屬性
參數群組: Pagination Arguments
--next-token

標記,指定要開始分頁的位置。 這是先前截斷回應中的令牌值。

屬性
參數群組: Pagination Arguments
全域參數
--debug

提高日誌詳細程度以顯示所有調試日誌。

屬性
預設值: False
--help -h

顯示此說明訊息並結束。

--only-show-errors

只顯示錯誤,隱藏警告。

屬性
預設值: False
--output -o

輸出格式。

屬性
預設值: json
接受的值: json, jsonc, none, table, tsv, yaml, yamlc
--query

JMESPath 查詢字串。 如需詳細資訊和範例,請參閱 http://jmespath.org/

--subscription

訂用帳戶的名稱或識別碼。 您可以使用 az account set -s NAME_OR_ID 設定預設訂用帳戶。

--verbose

增加記錄的詳細程度。 針對完整偵錯記錄使用 --debug。

屬性
預設值: False

az policy definition show

擷取原則定義。

擷取並顯示指定訂用帳戶或管理群組中具有指定名稱的原則定義詳細數據。

az policy definition show --name
                          [--management-group]

範例

擷取管理群組層級的原則定義

az policy definition show --management-group MyManagementGroup --name ResourceNaming

擷取原則定義

az policy definition show --name ResourceNaming

必要參數

--name -n

原則定義的名稱。

選擇性參數

下列參數是選擇性參數,但視內容而定,命令可能需要一或多個參數才能成功執行。

--management-group

管理小組。

全域參數
--debug

提高日誌詳細程度以顯示所有調試日誌。

屬性
預設值: False
--help -h

顯示此說明訊息並結束。

--only-show-errors

只顯示錯誤,隱藏警告。

屬性
預設值: False
--output -o

輸出格式。

屬性
預設值: json
接受的值: json, jsonc, none, table, tsv, yaml, yamlc
--query

JMESPath 查詢字串。 如需詳細資訊和範例,請參閱 http://jmespath.org/

--subscription

訂用帳戶的名稱或識別碼。 您可以使用 az account set -s NAME_OR_ID 設定預設訂用帳戶。

--verbose

增加記錄的詳細程度。 針對完整偵錯記錄使用 --debug。

屬性
預設值: False

az policy definition update

更新原則定義。

套用指定的屬性,以指定的名稱更新指定訂用帳戶或管理群組中的原則定義。

az policy definition update --name
                            [--add]
                            [--description]
                            [--display-name]
                            [--force-string {0, 1, f, false, n, no, t, true, y, yes}]
                            [--management-group]
                            [--metadata]
                            [--mode]
                            [--params]
                            [--remove]
                            [--rule --rules]
                            [--set]
                            [--version]

範例

更新原則定義顯示名稱

az policy definition update --name MyPolicyDefinition --display-name "Updated display name goes here"

必要參數

--name -n

原則定義的名稱。

選擇性參數

下列參數是選擇性參數,但視內容而定,命令可能需要一或多個參數才能成功執行。

--add

藉由指定路徑和索引鍵值組,將物件加入物件清單。 範例: --add property.listProperty <key=value, string or JSON string>.

屬性
參數群組: Generic Update Arguments
--description

原則定義描述。

屬性
參數群組: Properties Arguments
--display-name

原則定義的顯示名稱。

屬性
參數群組: Properties Arguments
--force-string

使用 'set' 或 'add' 時,請保留字串常值,而不是嘗試轉換成 JSON。

屬性
參數群組: Generic Update Arguments
接受的值: 0, 1, f, false, n, no, t, true, y, yes
--management-group

管理小組。

--metadata

原則定義中繼資料。 支援速記語法、json-file 和 yaml-file。 請嘗試 “??” 以顯示更多。

屬性
參數群組: Properties Arguments
--mode -m

原則定義模式。

屬性
參數群組: Properties Arguments
--params -p

原則規則參數定義。 支援速記語法、json-file 和 yaml-file。 請嘗試 “??” 以顯示更多。

屬性
參數群組: Properties Arguments
--remove

從清單中移除屬性或專案。 範例: --remove property.list <indexToRemove>--remove propertyToRemove

屬性
參數群組: Generic Update Arguments
--rule --rules

政策規則。 支援速記語法、json-file 和 yaml-file。 請嘗試 “??” 以顯示更多。

屬性
參數群組: Properties Arguments
--set

指定要設定的屬性路徑和值,以更新物件。 範例: --set property1.property2=<value>.

屬性
參數群組: Generic Update Arguments
--version

原則定義版本。

屬性
參數群組: Properties Arguments
全域參數
--debug

提高日誌詳細程度以顯示所有調試日誌。

屬性
預設值: False
--help -h

顯示此說明訊息並結束。

--only-show-errors

只顯示錯誤,隱藏警告。

屬性
預設值: False
--output -o

輸出格式。

屬性
預設值: json
接受的值: json, jsonc, none, table, tsv, yaml, yamlc
--query

JMESPath 查詢字串。 如需詳細資訊和範例,請參閱 http://jmespath.org/

--subscription

訂用帳戶的名稱或識別碼。 您可以使用 az account set -s NAME_OR_ID 設定預設訂用帳戶。

--verbose

增加記錄的詳細程度。 針對完整偵錯記錄使用 --debug。

屬性
預設值: False