Bylaw

Gallery › Compute › Azure Community Policy

Activate Azure Benefits for Windows Arc Machines

Converted Policy AuditIfNotExists DeployIfNotExists Disabled Mode Indexed Version 1.0.0

Activate Azure benefits for Windows ARC Machines

For 2025 server, if license type is Pay-as-you-go, then this will check Pay-as-you-go box in license menu. If 2025 and not Pay-as-you-go license or not 2025 server then check Software Assurance box. This policy only checks Windows Server resources and will NOT check unlicensed servers

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

Azure Policy JSONazurepolicy.json · 198 lines
{
  "name": "8afa5ca1-7115-489a-8b1f-209602402816",
  "type": "Microsoft.Authorization/policyDefinitions",
  "properties": {
    "displayName": "Activate Azure Benefits for Windows Arc Machines",
    "description": "Activate Azure benefits for Windows ARC Machines\n\nFor 2025 server, if license type is Pay-as-you-go, then this will check Pay-as-you-go box in license menu.  If 2025 and not Pay-as-you-go license or not 2025 server then check Software Assurance box.  This policy only checks Windows Server resources and will NOT check unlicensed servers",
    "metadata": {
      "version": "1.0.0",
      "category": "Compute"
    },
    "mode": "Indexed",
    "parameters": {
      "effect": {
        "type": "String",
        "metadata": {
          "displayName": "Effect",
          "description": "DeployIfNotExists, AuditIfNotExists or Disabled the execution of the Policy"
        },
        "allowedValues": [
          "DeployIfNotExists",
          "AuditIfNotExists",
          "Disabled"
        ],
        "defaultValue": "DeployIfNotExists"
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.HybridCompute/machines"
          },
          {
            "field": "Microsoft.HybridCompute/machines/osType",
            "equals": "windows"
          },
          {
            "field": "Microsoft.HybridCompute/machines/licenseProfile.licenseStatus",
            "equals": "Licensed"
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]",
        "details": {
          "type": "Microsoft.HybridCompute/machines",
          "name": "[field('name')]",
          "roleDefinitionIds": [
            "/providers/Microsoft.Authorization/roleDefinitions/b24988ac-6180-42a0-ab88-20f7382dd24c"
          ],
          "existenceCondition": {
            "anyOf": [
              {
                "allOf": [
                  {
                    "field": "Microsoft.HybridCompute/machines/osSku",
                    "contains": "2025"
                  },
                  {
                    "field": "Microsoft.HybridCompute/machines/licenseProfile.licenseChannel",
                    "contains": "PGS"
                  },
                  {
                    "anyOf": [
                      {
                        "field": "Microsoft.HybridCompute/machines/licenseProfile.productProfile.subscriptionStatus",
                        "equals": "Enabled"
                      },
                      {
                        "field": "Microsoft.HybridCompute/machines/licenseProfile.productProfile.productFeatures[*].subscriptionStatus",
                        "equals": "Enabled"
                      }
                    ]
                  }
                ]
              },
              {
                "allOf": [
                  {
                    "field": "Microsoft.HybridCompute/machines/osSku",
                    "contains": "2025"
                  },
                  {
                    "not": {
                      "field": "Microsoft.HybridCompute/machines/licenseProfile.licenseChannel",
                      "contains": "PGS"
                    }
                  },
                  {
                    "field": "Microsoft.HybridCompute/machines/licenseProfile.softwareAssurance.softwareAssuranceCustomer",
                    "equals": true
                  }
                ]
              },
              {
                "allOf": [
                  {
                    "not": {
                      "field": "Microsoft.HybridCompute/machines/osSku",
                      "contains": "2025"
                    }
                  },
                  {
                    "field": "Microsoft.HybridCompute/machines/licenseProfile.softwareAssurance.softwareAssuranceCustomer",
                    "equals": true
                  }
                ]
              }
            ]
          },
          "deployment": {
            "properties": {
              "mode": "incremental",
              "template": {
                "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
                "contentVersion": "1.0.0.0",
                "parameters": {
                  "vmName": {
                    "type": "string"
                  },
                  "location": {
                    "type": "string"
                  },
                  "osSku": {
                    "type": "string"
                  },
                  "licenseChannel": {
                    "type": "string"
                  },
                  "status": {
                    "type": "string"
                  },
                  "productType": {
                    "type": "string"
                  }
                },
                "resources": [
                  {
                    "condition": "[and(equals(parameters('status'), 'Connected'), contains(parameters('licenseChannel'), 'PGS'))]",
                    "name": "[concat(parameters('vmName'), '/default')]",
                    "type": "Microsoft.HybridCompute/machines/licenseProfiles",
                    "location": "[parameters('location')]",
                    "apiVersion": "2025-01-13",
                    "properties": {
                      "productProfile": {
                        "productType": "[parameters('productType')]",
                        "subscriptionStatus": "Enabled"
                      }
                    }
                  },
                  {
                    "condition": "[and(equals(parameters('status'), 'Connected'), not(contains(parameters('licenseChannel'), 'PGS')))]",
                    "name": "[concat(parameters('vmName'), '/default')]",
                    "type": "Microsoft.HybridCompute/machines/licenseProfiles",
                    "location": "[parameters('location')]",
                    "apiVersion": "2025-01-13",
                    "properties": {
                      "softwareAssurance": {
                        "softwareAssuranceCustomer": true
                      }
                    }
                  }
                ],
                "outputs": {
                  "policy": {
                    "type": "string",
                    "value": "[concat('Enabled Software Assurance for VM', ': ', parameters('vmName'))]"
                  }
                }
              },
              "parameters": {
                "vmName": {
                  "value": "[field('name')]"
                },
                "location": {
                  "value": "[field('location')]"
                },
                "osSku": {
                  "value": "[field('Microsoft.HybridCompute/machines/osSku')]"
                },
                "licenseChannel": {
                  "value": "[field('Microsoft.HybridCompute/machines/licenseProfile.licenseChannel')]"
                },
                "status": {
                  "value": "[field('Microsoft.HybridCompute/machines/status')]"
                },
                "productType": {
                  "value": "[field('Microsoft.HybridCompute/machines/licenseProfile.productProfile.productType')]"
                }
              }
            }
          }
        }
      }
    }
  }
}
Bylaw8afa5ca1-7115-489a-8b1f-209602402816.bylaw.ps1 · 68 lines
# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy '8afa5ca1-7115-489a-8b1f-209602402816' {

    Properties @{
        DisplayName = 'Activate Azure Benefits for Windows Arc Machines'
        Description = 'Activate Azure benefits for Windows ARC Machines

For 2025 server, if license type is Pay-as-you-go, then this will check Pay-as-you-go box in license menu.  If 2025 and not Pay-as-you-go license or not 2025 server then check Software Assurance box.  This policy only checks Windows Server resources and will NOT check unlicensed servers'
        Version     = '1.0.0'
        Category    = 'Compute'
        Mode        = 'Indexed'
    }

    Parameter Effect @{
        AllowedValues = @('DeployIfNotExists', 'AuditIfNotExists', 'Disabled')
        Default       = 'DeployIfNotExists'
        DisplayName   = 'Effect'
        Description   = 'DeployIfNotExists, AuditIfNotExists or Disabled the execution of the Policy'
    }

    Resource 'Microsoft.HybridCompute/machines' {

        When {
            Field osType | Must -Be 'windows'
        }

        Require 'licenseProfile.licenseStatus is not Licensed' {
            Field licenseProfile.licenseStatus | Must -Not -Be 'Licensed' -IfPresent
        }
    }

    DeployIfNotExists 'Microsoft.HybridCompute/machines' -Role 'Contributor' -Name (Arm '[field(''name'')]') -Effect (Param Effect) {
        Require 'osSku, licenseProfile.licenseChannel, licenseProfile.productProfile.subscriptionStatus and 3 more are as required' {
            AnyOf {
                AllOf {
                    Field osSku | Must -ContainText '2025'
                    Field licenseProfile.licenseChannel | Must -ContainText 'PGS'
                    AnyOf {
                        Field licenseProfile.productProfile.subscriptionStatus | Must -Be 'Enabled'
                        AllOf {
                            Field licenseProfile.productProfile.productFeatures | Must -Exist
                            Each 'licenseProfile.productProfile.productFeatures[*]' {
                                Field subscriptionStatus | Must -Be 'Enabled' -Strict
                            }
                        }
                    }
                }
                AllOf {
                    Field osSku | Must -ContainText '2025'
                    Field licenseProfile.licenseChannel | Must -Not -ContainText 'PGS' -IfPresent
                    Field licenseProfile.softwareAssurance.softwareAssuranceCustomer | Must -Be $true
                }
                AllOf {
                    Field osSku | Must -Not -ContainText '2025' -IfPresent
                    Field licenseProfile.softwareAssurance.softwareAssuranceCustomer | Must -Be $true
                }
            }
        }
        Deployment -TemplateFile './templates/8afa5ca1-7115-489a-8b1f-209602402816.json' -Parameters ([ordered]@{
                vmName         = (Arm '[field(''name'')]')
                location       = (Arm '[field(''location'')]')
                osSku          = (Arm '[field(''Microsoft.HybridCompute/machines/osSku'')]')
                licenseChannel = (Arm '[field(''Microsoft.HybridCompute/machines/licenseProfile.licenseChannel'')]')
                status         = (Arm '[field(''Microsoft.HybridCompute/machines/status'')]')
                productType    = (Arm '[field(''Microsoft.HybridCompute/machines/licenseProfile.productProfile.productType'')]')
            })
    }
}

Its deployment templates are written beside it:

Source: policyDefinitions/Compute/activate-azure-benefits-for-windows-arc-machines/azurepolicy.json in Azure/Community-Policy, under the MIT licence.