Bylaw

Gallery › Guest Configuration › Azure built-in policies

[Preview]: Audit Windows machines that do not have Windows Recovery Environment (WinRE) enabled

Converted Policy AuditIfNotExists Disabled Mode Indexed Version 1.0.0-preview Preview

Audits Windows machines to check if the Windows Recovery Environment (WinRE) is enabled

ConvertTo-Bylaw converted this policy, and proved that the file compiles back to the same definition.

Azure Policy JSONAuditWinREStatus_AINE.json · 82 lines
{
  "properties": {
    "displayName": "[Preview]: Audit Windows machines that do not have Windows Recovery Environment (WinRE) enabled",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "description": "Audits Windows machines to check if the Windows Recovery Environment (WinRE) is enabled",
    "metadata": {
      "version": "1.0.0-preview",
      "category": "Guest Configuration",
      "preview": true,
      "requiredProviders": [
        "Microsoft.GuestConfiguration"
      ],
      "guestConfiguration": {
        "name": "AuditWinREStatus",
        "version": "1.*"
      }
    },
    "version": "1.0.0-preview",
    "parameters": {
      "IncludeArcMachines": {
        "type": "string",
        "metadata": {
          "displayName": "Include Arc connected servers",
          "description": "By selecting this option, you agree to be charged monthly per Arc connected machine.",
          "portalReview": "true"
        },
        "allowedValues": [
          "true",
          "false"
        ],
        "defaultValue": "false"
      },
      "effect": {
        "type": "string",
        "metadata": {
          "displayName": "Effect",
          "description": "Enable or disable the execution of this policy"
        },
        "allowedValues": [
          "AuditIfNotExists",
          "Disabled"
        ],
        "defaultValue": "AuditIfNotExists"
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.HybridCompute/machines"
          },
          {
            "value": "[parameters('IncludeArcMachines')]",
            "equals": "true"
          },
          {
            "field": "Microsoft.HybridCompute/imageOffer",
            "like": "windows*"
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]",
        "details": {
          "type": "Microsoft.GuestConfiguration/guestConfigurationAssignments",
          "name": "AuditWinREStatus",
          "existenceCondition": {
            "field": "Microsoft.GuestConfiguration/guestConfigurationAssignments/complianceStatus",
            "equals": "Compliant"
          }
        }
      }
    },
    "versions": [
      "1.0.0-PREVIEW"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/ea13dcd3-9b62-4fa0-9462-1695a76d0e59",
  "name": "ea13dcd3-9b62-4fa0-9462-1695a76d0e59"
}
Bylawea13dcd3-9b62-4fa0-9462-1695a76d0e59.bylaw.ps1 · 48 lines
# Converted from AuditWinREStatus_AINE.json by ConvertTo-Bylaw.
Policy 'ea13dcd3-9b62-4fa0-9462-1695a76d0e59' {

    Properties @{
        DisplayName   = '[Preview]: Audit Windows machines that do not have Windows Recovery Environment (WinRE) enabled'
        Description   = 'Audits Windows machines to check if the Windows Recovery Environment (WinRE) is enabled'
        Version       = '1.0.0-preview'
        Category      = 'Guest Configuration'
        Preview       = $true
        PolicyVersion = '1.0.0-preview'
        Mode          = 'Indexed'
        Metadata      = [ordered]@{ requiredProviders = @('Microsoft.GuestConfiguration'); guestConfiguration = [ordered]@{ name = 'AuditWinREStatus'; version = '1.*' } }
    }

    Parameter IncludeArcMachines @{
        Type          = 'string'
        AllowedValues = @('true', 'false')
        Default       = 'false'
        DisplayName   = 'Include Arc connected servers'
        Description   = 'By selecting this option, you agree to be charged monthly per Arc connected machine.'
        JsonName      = 'IncludeArcMachines'
        Metadata      = [ordered]@{ portalReview = 'true' }
    }
    Parameter Effect @{
        Type          = 'string'
        AllowedValues = @('AuditIfNotExists', 'Disabled')
        Default       = 'AuditIfNotExists'
        DisplayName   = 'Effect'
        Description   = 'Enable or disable the execution of this policy'
    }

    Resource 'Microsoft.HybridCompute/machines' {

        When {
            Param IncludeArcMachines | Must -Be 'true'
        }

        Require 'imageOffer is not like windows*' {
            Field 'Microsoft.HybridCompute/imageOffer' | Must -Not -BeLike 'windows*' -IfPresent
        }
    }

    AuditIfNotExists 'Microsoft.GuestConfiguration/guestConfigurationAssignments' -Name 'AuditWinREStatus' -Effect (Param Effect) {
        Require 'complianceStatus is Compliant' {
            Field complianceStatus | Must -Be 'Compliant'
        }
    }
}

Source: built-in-policies/policyDefinitions/Guest Configuration/AuditWinREStatus_AINE.json in Azure/azure-policy, under the MIT licence.