Gallery › ChangeTrackingAndInventory › Azure built-in policies
Configure Windows VMSS to be associated with a Data Collection Rule for ChangeTracking and Inventory
Converted Policy DeployIfNotExists Disabled Mode Indexed Version 1.2.0
Deploy Association to link Windows virtual machine scale sets to specified Data Collection Rule to enable ChangeTracking and Inventory. The list of locations and OS images are updated over time as support is increased.
ConvertTo-Bylaw converted this policy, and proved that the file compiles back to the same definition.
Azure Policy JSONDCRA_Windows_VMSS_DINE.json · 365 lines
{
"properties": {
"displayName": "Configure Windows VMSS to be associated with a Data Collection Rule for ChangeTracking and Inventory",
"policyType": "BuiltIn",
"mode": "Indexed",
"description": "Deploy Association to link Windows virtual machine scale sets to specified Data Collection Rule to enable ChangeTracking and Inventory. The list of locations and OS images are updated over time as support is increased.",
"metadata": {
"version": "1.2.0",
"category": "ChangeTrackingAndInventory"
},
"version": "1.2.0",
"parameters": {
"effect": {
"type": "String",
"metadata": {
"displayName": "Effect",
"description": "Enable or disable the execution of the policy."
},
"allowedValues": [
"DeployIfNotExists",
"Disabled"
],
"defaultValue": "DeployIfNotExists"
},
"dcrResourceId": {
"type": "String",
"metadata": {
"displayName": "Data Collection Rule Resource Id",
"description": "Resource Id of the Data Collection Rule to be applied on the virtual machine sets in scope."
}
},
"listOfApplicableLocations": {
"type": "Array",
"metadata": {
"displayName": "Applicable Locations",
"description": "The list of locations where the policy should be applied.",
"strongType": "location"
},
"allowedValues": [
"australiasoutheast",
"australiaeast",
"brazilsouth",
"canadacentral",
"centralindia",
"centralus",
"eastasia",
"eastus2euap",
"eastus",
"eastus2",
"francecentral",
"japaneast",
"koreacentral",
"northcentralus",
"northeurope",
"norwayeast",
"southcentralus",
"southeastasia",
"switzerlandnorth",
"uaenorth",
"uksouth",
"westcentralus",
"westeurope",
"westus",
"westus2"
],
"defaultValue": [
"australiasoutheast",
"australiaeast",
"brazilsouth",
"canadacentral",
"centralindia",
"centralus",
"eastasia",
"eastus2euap",
"eastus",
"eastus2",
"francecentral",
"japaneast",
"koreacentral",
"northcentralus",
"northeurope",
"norwayeast",
"southcentralus",
"southeastasia",
"switzerlandnorth",
"uaenorth",
"uksouth",
"westcentralus",
"westeurope",
"westus",
"westus2"
]
}
},
"policyRule": {
"if": {
"allOf": [
{
"field": "type",
"equals": "Microsoft.Compute/virtualMachineScaleSets"
},
{
"field": "location",
"in": "[parameters('listOfApplicableLocations')]"
},
{
"anyOf": [
{
"allOf": [
{
"field": "Microsoft.Compute/imagePublisher",
"equals": "MicrosoftWindowsServer"
},
{
"field": "Microsoft.Compute/imageOffer",
"equals": "WindowsServer"
},
{
"anyOf": [
{
"field": "Microsoft.Compute/imageSku",
"like": "2008-R2-SP1*"
},
{
"field": "Microsoft.Compute/imageSku",
"like": "2012-*"
},
{
"field": "Microsoft.Compute/imageSku",
"like": "2016-*"
},
{
"field": "Microsoft.Compute/imageSku",
"like": "2019-*"
},
{
"field": "Microsoft.Compute/imageSku",
"like": "2022-*"
},
{
"field": "Microsoft.Compute/imageSku",
"like": "2025-*"
}
]
}
]
},
{
"allOf": [
{
"field": "Microsoft.Compute/imagePublisher",
"equals": "MicrosoftWindowsServer"
},
{
"field": "Microsoft.Compute/imageOffer",
"equals": "WindowsServerSemiAnnual"
},
{
"field": "Microsoft.Compute/imageSKU",
"in": [
"Datacenter-Core-1709-smalldisk",
"Datacenter-Core-1709-with-Containers-smalldisk",
"Datacenter-Core-1803-with-Containers-smalldisk",
"Datacenter-Core-1809-with-Containers-smalldisk"
]
}
]
},
{
"allOf": [
{
"field": "Microsoft.Compute/imagePublisher",
"equals": "MicrosoftWindowsServerHPCPack"
},
{
"field": "Microsoft.Compute/imageOffer",
"equals": "WindowsServerHPCPack"
}
]
},
{
"allOf": [
{
"field": "Microsoft.Compute/imagePublisher",
"equals": "MicrosoftSQLServer"
},
{
"anyOf": [
{
"field": "Microsoft.Compute/imageOffer",
"like": "*-WS2016"
},
{
"field": "Microsoft.Compute/imageOffer",
"like": "*-WS2016-BYOL"
},
{
"field": "Microsoft.Compute/imageOffer",
"like": "*-WS2012R2"
},
{
"field": "Microsoft.Compute/imageOffer",
"like": "*-WS2012R2-BYOL"
}
]
}
]
},
{
"allOf": [
{
"field": "Microsoft.Compute/imagePublisher",
"equals": "MicrosoftRServer"
},
{
"field": "Microsoft.Compute/imageOffer",
"equals": "MLServer-WS2016"
}
]
},
{
"allOf": [
{
"field": "Microsoft.Compute/imagePublisher",
"equals": "MicrosoftVisualStudio"
},
{
"field": "Microsoft.Compute/imageOffer",
"in": [
"VisualStudio",
"Windows"
]
}
]
},
{
"allOf": [
{
"field": "Microsoft.Compute/imagePublisher",
"equals": "MicrosoftDynamicsAX"
},
{
"field": "Microsoft.Compute/imageOffer",
"equals": "Dynamics"
},
{
"field": "Microsoft.Compute/imageSKU",
"equals": "Pre-Req-AX7-Onebox-U8"
}
]
},
{
"allOf": [
{
"field": "Microsoft.Compute/imagePublisher",
"equals": "microsoft-ads"
},
{
"field": "Microsoft.Compute/imageOffer",
"equals": "windows-data-science-vm"
}
]
},
{
"allOf": [
{
"field": "Microsoft.Compute/imagePublisher",
"equals": "MicrosoftWindowsDesktop"
},
{
"field": "Microsoft.Compute/imageOffer",
"equals": "Windows-10"
}
]
},
{
"allOf": [
{
"field": "Microsoft.Compute/imagePublisher",
"equals": "center-for-internet-security-inc"
},
{
"field": "Microsoft.Compute/imageOffer",
"equals": "cis-windows-server"
},
{
"field": "Microsoft.Compute/imageSKU",
"equals": "cis-windows-server2022-l1-gen1"
}
]
}
]
}
]
},
"then": {
"effect": "[parameters('effect')]",
"details": {
"type": "Microsoft.Insights/dataCollectionRuleAssociations",
"roleDefinitionIds": [
"/providers/microsoft.authorization/roleDefinitions/749f88d5-cbae-40b8-bcfc-e573ddc772fa",
"/providers/microsoft.authorization/roleDefinitions/92aaf0da-9dab-42b6-94a3-d43ce8d16293"
],
"existenceCondition": {
"field": "Microsoft.Insights/dataCollectionRuleAssociations/dataCollectionRuleId",
"equals": "[parameters('dcrResourceId')]"
},
"deployment": {
"properties": {
"mode": "incremental",
"template": {
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"resourceName": {
"type": "string"
},
"location": {
"type": "string"
},
"dcrResourceId": {
"type": "string"
}
},
"variables": {
"associationName": "[concat('ct-', uniqueString(parameters('dcrResourceId')))]"
},
"resources": [
{
"name": "[variables('associationName')]",
"type": "Microsoft.Insights/dataCollectionRuleAssociations",
"apiVersion": "2021-04-01",
"properties": {
"dataCollectionRuleId": "[parameters('dcrResourceId')]"
},
"scope": "[concat('Microsoft.Compute/virtualMachineScaleSets/', parameters('resourceName'))]"
}
]
},
"parameters": {
"resourceName": {
"value": "[field('name')]"
},
"location": {
"value": "[field('location')]"
},
"dcrResourceId": {
"value": "[parameters('dcrResourceId')]"
}
}
}
}
}
}
},
"versions": [
"1.2.0",
"1.1.0",
"1.0.1",
"1.0.0-PREVIEW"
]
},
"id": "/providers/Microsoft.Authorization/policyDefinitions/8fd85785-1547-4a4a-bf90-d5483c9571c5",
"name": "8fd85785-1547-4a4a-bf90-d5483c9571c5"
}Bylaw8fd85785-1547-4a4a-bf90-d5483c9571c5.bylaw.ps1 · 136 lines
# Converted from DCRA_Windows_VMSS_DINE.json by ConvertTo-Bylaw.
Policy '8fd85785-1547-4a4a-bf90-d5483c9571c5' {
Properties @{
DisplayName = 'Configure Windows VMSS to be associated with a Data Collection Rule for ChangeTracking and Inventory'
Description = 'Deploy Association to link Windows virtual machine scale sets to specified Data Collection Rule to enable ChangeTracking and Inventory. The list of locations and OS images are updated over time as support is increased.'
Version = '1.2.0'
Category = 'ChangeTrackingAndInventory'
PolicyVersion = '1.2.0'
Mode = 'Indexed'
}
Parameter Effect @{
AllowedValues = @('DeployIfNotExists', 'Disabled')
Default = 'DeployIfNotExists'
DisplayName = 'Effect'
Description = 'Enable or disable the execution of the policy.'
}
Parameter DcrResourceId @{
Type = 'String'
DisplayName = 'Data Collection Rule Resource Id'
Description = 'Resource Id of the Data Collection Rule to be applied on the virtual machine sets in scope.'
}
Parameter ListOfApplicableLocations @{
Type = 'Array'
AllowedValues = @('australiasoutheast', 'australiaeast', 'brazilsouth', 'canadacentral', 'centralindia', 'centralus', 'eastasia', 'eastus2euap', 'eastus', 'eastus2', 'francecentral', 'japaneast', 'koreacentral', 'northcentralus', 'northeurope', 'norwayeast', 'southcentralus', 'southeastasia', 'switzerlandnorth', 'uaenorth', 'uksouth', 'westcentralus', 'westeurope', 'westus', 'westus2')
Default = @('australiasoutheast', 'australiaeast', 'brazilsouth', 'canadacentral', 'centralindia', 'centralus', 'eastasia', 'eastus2euap', 'eastus', 'eastus2', 'francecentral', 'japaneast', 'koreacentral', 'northcentralus', 'northeurope', 'norwayeast', 'southcentralus', 'southeastasia', 'switzerlandnorth', 'uaenorth', 'uksouth', 'westcentralus', 'westeurope', 'westus', 'westus2')
DisplayName = 'Applicable Locations'
Description = 'The list of locations where the policy should be applied.'
Metadata = [ordered]@{ strongType = 'location' }
}
Resource 'Microsoft.Compute/virtualMachineScaleSets' {
When {
Field location | Must -BeIn (Param ListOfApplicableLocations)
}
Require 'imagePublisher, imageOffer and imageSku are as required' {
AnyOf {
Field 'Microsoft.Compute/imagePublisher' | Must -Not -Be 'MicrosoftWindowsServer' -IfPresent
Field 'Microsoft.Compute/imageOffer' | Must -Not -Be 'WindowsServer' -IfPresent
AllOf {
Field 'Microsoft.Compute/imageSku' | Must -Not -BeLike '2008-R2-SP1*' -IfPresent
Field 'Microsoft.Compute/imageSku' | Must -Not -BeLike '2012-*' -IfPresent
Field 'Microsoft.Compute/imageSku' | Must -Not -BeLike '2016-*' -IfPresent
Field 'Microsoft.Compute/imageSku' | Must -Not -BeLike '2019-*' -IfPresent
Field 'Microsoft.Compute/imageSku' | Must -Not -BeLike '2022-*' -IfPresent
Field 'Microsoft.Compute/imageSku' | Must -Not -BeLike '2025-*' -IfPresent
}
}
}
Require 'imagePublisher, imageOffer and imageSKU are as required' {
AnyOf {
Field 'Microsoft.Compute/imagePublisher' | Must -Not -Be 'MicrosoftWindowsServer' -IfPresent
Field 'Microsoft.Compute/imageOffer' | Must -Not -Be 'WindowsServerSemiAnnual' -IfPresent
Field 'Microsoft.Compute/imageSKU' | Must -Not -BeIn @('Datacenter-Core-1709-smalldisk', 'Datacenter-Core-1709-with-Containers-smalldisk', 'Datacenter-Core-1803-with-Containers-smalldisk', 'Datacenter-Core-1809-with-Containers-smalldisk') -IfPresent
}
}
Require 'imagePublisher and imageOffer are as required' {
AnyOf {
Field 'Microsoft.Compute/imagePublisher' | Must -Not -Be 'MicrosoftWindowsServerHPCPack' -IfPresent
Field 'Microsoft.Compute/imageOffer' | Must -Not -Be 'WindowsServerHPCPack' -IfPresent
}
}
Require 'imagePublisher and imageOffer are as required' {
AnyOf {
Field 'Microsoft.Compute/imagePublisher' | Must -Not -Be 'MicrosoftSQLServer' -IfPresent
AllOf {
Field 'Microsoft.Compute/imageOffer' | Must -Not -BeLike '*-WS2016' -IfPresent
Field 'Microsoft.Compute/imageOffer' | Must -Not -BeLike '*-WS2016-BYOL' -IfPresent
Field 'Microsoft.Compute/imageOffer' | Must -Not -BeLike '*-WS2012R2' -IfPresent
Field 'Microsoft.Compute/imageOffer' | Must -Not -BeLike '*-WS2012R2-BYOL' -IfPresent
}
}
}
Require 'imagePublisher and imageOffer are as required' {
AnyOf {
Field 'Microsoft.Compute/imagePublisher' | Must -Not -Be 'MicrosoftRServer' -IfPresent
Field 'Microsoft.Compute/imageOffer' | Must -Not -Be 'MLServer-WS2016' -IfPresent
}
}
Require 'imagePublisher and imageOffer are as required' {
AnyOf {
Field 'Microsoft.Compute/imagePublisher' | Must -Not -Be 'MicrosoftVisualStudio' -IfPresent
Field 'Microsoft.Compute/imageOffer' | Must -Not -BeIn @('VisualStudio', 'Windows') -IfPresent
}
}
Require 'imagePublisher, imageOffer and imageSKU are as required' {
AnyOf {
Field 'Microsoft.Compute/imagePublisher' | Must -Not -Be 'MicrosoftDynamicsAX' -IfPresent
Field 'Microsoft.Compute/imageOffer' | Must -Not -Be 'Dynamics' -IfPresent
Field 'Microsoft.Compute/imageSKU' | Must -Not -Be 'Pre-Req-AX7-Onebox-U8' -IfPresent
}
}
Require 'imagePublisher and imageOffer are as required' {
AnyOf {
Field 'Microsoft.Compute/imagePublisher' | Must -Not -Be 'microsoft-ads' -IfPresent
Field 'Microsoft.Compute/imageOffer' | Must -Not -Be 'windows-data-science-vm' -IfPresent
}
}
Require 'imagePublisher and imageOffer are as required' {
AnyOf {
Field 'Microsoft.Compute/imagePublisher' | Must -Not -Be 'MicrosoftWindowsDesktop' -IfPresent
Field 'Microsoft.Compute/imageOffer' | Must -Not -Be 'Windows-10' -IfPresent
}
}
Require 'imagePublisher, imageOffer and imageSKU are as required' {
AnyOf {
Field 'Microsoft.Compute/imagePublisher' | Must -Not -Be 'center-for-internet-security-inc' -IfPresent
Field 'Microsoft.Compute/imageOffer' | Must -Not -Be 'cis-windows-server' -IfPresent
Field 'Microsoft.Compute/imageSKU' | Must -Not -Be 'cis-windows-server2022-l1-gen1' -IfPresent
}
}
}
DeployIfNotExists 'Microsoft.Insights/dataCollectionRuleAssociations' -Role 'Monitoring Contributor', 'Log Analytics Contributor' -Effect (Param Effect) {
Require 'dataCollectionRuleId is the DcrResourceId parameter' {
Field dataCollectionRuleId | Must -Be (Param DcrResourceId)
}
Deployment -TemplateFile './templates/8fd85785-1547-4a4a-bf90-d5483c9571c5.json' -Parameters ([ordered]@{
resourceName = (Arm '[field(''name'')]')
location = (Arm '[field(''location'')]')
dcrResourceId = (Param DcrResourceId)
})
}
}Its deployment templates are written beside it:
templates/8fd85785-1547-4a4a-bf90-d5483c9571c5.json
Source: built-in-policies/policyDefinitions/ChangeTrackingAndInventory/DCRA_Windows_VMSS_DINE.json in Azure/azure-policy, under the MIT licence.
Bylaw