了解機器設定指派資源

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

請參閱此文件的逐步解說影片 (英文)

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

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

Azure 原則如何使用機器設定指派

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

從 Azure 原則刪除來賓指派

刪除 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 內容套件 MOF 檔案內的組態名稱。
contentUri 內容套件 (.zip) 的 HTTPS URI 路徑。
contentHash 內容套件的 SHA256 雜湊值,用於驗證是否尚未變更。
version 內容套件的版本。 僅用於內建套件,不適用於自訂的內容套件。
assignmentType 指派的行為。 允許值:AuditApplyandMonitorApplyandAutoCorrect
configurationParameter 將內容套件 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

下一步