How to add Dependency Agent to VM in Azure using PowerShell and ARM Template

Some solutions in OMS like Network Performance Monitor or Service Map require Dependency Agent installed on Virtual Machine. Let's try to add this in the most efficient way.

ARM Template

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0",
    "parameters": {
        "vmName":{
            "type": "string",
            "metadata": {
                "Description": "VM name"
            }
        }
    },
    "variables": {},
    "resources": [
        {
            "type": "Microsoft.Compute/virtualMachines/extensions",
            "name": "[concat(parameters('vmName'), '/DependencyAgent')]",
            "apiVersion": "2017-03-30",
            "location": "West Europe",
            "properties": {
                "publisher": "Microsoft.Azure.Monitoring.DependencyAgent",
                "type": "DependencyAgentWindows",
                "typeHandlerVersion": "9.3",
                "autoUpgradeMinorVersion": true
            }
        }
    ],
    "outputs": {}
}

PowerShell to deploy

New-AzureRmResourceGroupDeployment -Name "DependencyAgent" -ResourceGroupName $ResourceGroup -TemplateFile ".\dependency-agent.json" -vmName VMname