Public/IaaS/vm/Set-CmAzIaasUpdateManagement.json

{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "AutomationAccountName": {
            "type": "string"
        },
        "UpdateSchedules": {
            "type": "array"
        }
    },
    "resources": [
        {
            "type": "Microsoft.Resources/Deployments",
            "apiVersion": "2019-10-01",
            "name": "[concat('ScheduleTemplates', copyIndex('ScheduleCopy'))]",
            "copy": {
                "name": "ScheduleCopy",
                "count": "[length(parameters('UpdateSchedules'))]"
            },
            "properties": {
                "mode": "Incremental",
                "expressionEvaluationOptions": {
                    "scope": "inner"
                },
                "parameters": {
                    "AutomationAccountName": {
                        "value": "[parameters('AutomationAccountName')]"
                    },
                    "UpdateSchedule": {
                        "value": "[parameters('UpdateSchedules')[copyIndex('ScheduleCopy')]]"
                    }
                },
                "template": {
                    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
                    "contentVersion": "1.0.0.0",
                    "parameters": {
                        "AutomationAccountName": {
                            "type": "String"
                        },
                        "UpdateSchedule": {
                            "type": "Object"
                        }
                    },
                    "resources": [
                        {
                            "type": "Microsoft.Automation/automationAccounts/schedules",
                            "apiVersion": "2015-10-31",
                            "name": "[concat(parameters('AutomationAccountName'), '/', parameters('UpdateSchedule').details.name)]",
                            "properties": "[parameters('UpdateSchedule').details]"
                        },
                        {
                            "type": "Microsoft.Automation/automationAccounts/jobSchedules",
                            "apiVersion": "2015-10-31",
                            "name": "[concat(parameters('AutomationAccountName'), '/', Guid(concat(parameters('AutomationAccountName'), parameters('UpdateSchedule').details.name)))]",
                            "dependsOn": [
                                "[concat('Microsoft.Automation/automationAccounts/', parameters('AutomationAccountName'), '/schedules/', parameters('UpdateSchedule').details.name)]"
                            ],
                            "properties": {
                                "runbook": {
                                    "name": "Patch-MicrosoftOMSComputers"
                                },
                                "schedule": {
                                    "name": "[parameters('UpdateSchedule').details.name]"
                                }
                            }
                        },
                        {
                            "type": "Microsoft.Automation/automationAccounts/softwareUpdateConfigurations",
                            "apiVersion": "2017-05-15-preview",
                            "name": "[concat(parameters('AutomationAccountName'), '/', parameters('UpdateSchedule').details.name)]",
                            "properties": {
                                "updateConfiguration": {
                                    "operatingSystem": "Windows",
                                    "windows": {
                                        "includedUpdateClassifications": "[parameters('UpdateSchedule').updateTypes]",
                                        "rebootSetting": "IfRequired"
                                    },
                                    "targets": {
                                        "azureQueries": [
                                            {
                                                "scope": [
                                                    "[subscription().Id]"
                                                ],
                                                "tagSettings": {
                                                    "tags": {
                                                        "cm-update": [
                                                            "[parameters('UpdateSchedule').tagValue]"
                                                        ]
                                                    },
                                                    "filterOperator": "Any"
                                                },
                                                "locations": [
                                                    "[parameters('UpdateSchedule').location]"
                                                ]
                                            }
                                        ]
                                    },
                                    "duration": "PT6H"
                                },
                                "tasks": {},
                                "scheduleInfo": "[parameters('UpdateSchedule').details]"
                            }
                        }
                    ]
                }
            }
        }
    ]
}