共用方式為


瞭解機器配置和分配資源

若指派的 Azure 原則屬於 Guest Configuration 類別,便會包含中繼資料以描述客體指派。

可以觀看此文件的影片導覽

您可以將來賓指派視為機器與 Azure 原則案例之間的連結。 例如,Azure Windows 基準組態會透過下列程式碼片段,與原則範圍內的電腦最低版本 1.0.0 建立關聯。

"metadata": {
    "category": "Guest Configuration",
    "guestConfiguration": {
        "name": "AzureWindowsBaseline",
        "version": "1.*"
    }
  //additional metadata properties exist
}

Azure Policy 如何運用機器配置指派

機器配置服務會使用中繼資料資訊,為具有AuditIfNotExistsDeployIfNotExists原則效果的定義自動建立稽核資源。 資源類型為 Microsoft.GuestConfiguration/guestConfigurationAssignments。 Azure 原則會使用來賓指派資源的 complianceStatus 屬性來報告合規性狀態。 如需詳細資訊,請參閱 取得合規性資料

備註

當指派自訂原則以部署來賓設定時,來賓指派資源上的 assignmentType 屬性可能會暫時顯示為 Null,然後會更新為反映原則定義中指定的值。 這是預期行為,通常會在一小時內解決。

從 Azure Policy 刪除來賓指派

刪除 Azure 原則指派時,如果原則已建立機器設定指派,則也會刪除機器設定指派。

從方案中刪除 Azure 原則指派時,您必須手動刪除原則所建立的任何機器設定指派。 您可以流覽至 Azure 入口網站上的來賓指派頁面,然後刪除該處的指派。

手動建立機器配置指派

您可以使用 Azure 原則或任何用戶端 SDK,在 Azure Resource Manager 中建立來賓指派資源。

部署範本範例:

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "resources": [
    {
      "apiVersion": "2021-01-25",
      "type": "Microsoft.Compute/virtualMachines/providers/guestConfigurationAssignments",
      "name": "myMachine/Microsoft.GuestConfiguration/myConfig",
      "location": "westus2",
      "properties": {
        "guestConfiguration": {
          "name": "myConfig",
          "contentUri": "https://mystorageaccount.blob.core.windows.net/mystoragecontainer/myConfig.zip?sv=SASTOKEN",
          "contentHash": "SHA256HASH",
          "version": "1.0.0",
          "assignmentType": "ApplyAndMonitor",
          "configurationParameter": [
            "name":"configurationName",
            "value":"configurationValue"
          ]
        }
      }
    }
  ]
}

configurationParameter範例:

   "configurationParameter": [
        {
          "name": "[SecureWebServer]s1;MinimumTLSVersion",
          "value": "1.2"
        }
      ],

下表說明來賓指派資源的每個屬性。

房產 Description
name 內容套件 MOF 檔案內的設定名稱。
contentUri 內容套件的HTTPS URI路徑(.zip)。
內容雜湊 內容包的 SHA256 雜湊值,用來驗證它未變更。
version 內容套件的版本。 僅用於內建套件,不用於自訂內容套件。
指定類型 指派的行為。 允許值:AuditApplyandMonitorApplyandAutoCorrect
組態參數 將內容套件 MOF 檔案下載至電腦後,其中要覆寫的 DSC 資源類型、名稱和值清單。

刪除手動建立的電腦組態指派

您必須手動刪除透過任何手動方法 (例如 Azure Resource Manager 範本部署) 建立的機器設定指派。 刪除父資源 (虛擬機器或已啟用 Arc 的機器) 也會刪除機器設定指派。

若要手動刪除電腦組態指派,請使用下列範例。 請務必取代所有範例字串,以括弧表示 <>

# First get details about the machine configuration assignment
$resourceDetails = @{
  ResourceGroupName = '<resource-group-name>'
  ResourceType      = 'Microsoft.Compute/virtualMachines/providers/guestConfigurationAssignments/'
  ResourceName      = '<vm-name>/Microsoft.GuestConfiguration'
  ApiVersion        = '2020-06-25'
}
$guestAssignment = Get-AzResource @resourceDetails

# Review details of the machine configuration assignment
$guestAssignment

# After reviewing properties of $guestAssignment to confirm
$guestAssignment | Remove-AzResource

後續步驟