Skip to content

Instantly share code, notes, and snippets.

@biacz
Created April 7, 2021 23:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save biacz/c134fd53fb10f33a688a339904ca7faf to your computer and use it in GitHub Desktop.
Save biacz/c134fd53fb10f33a688a339904ca7faf to your computer and use it in GitHub Desktop.
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"artifactsLocation": {
"defaultValue": "https://wvdportalstorageblob.blob.core.windows.net/galleryartifacts/Configuration.zip",
"type": "String",
"metadata": {
"description": "The base URI where artifacts required by this template are located."
}
},
"VmImageVhdUri": {
"type": "String",
"metadata": {
"description": "URI of the sysprepped image vhd file to be used to create the session host VMs. For example, https://rdsstorage.blob.core.windows.net/vhds/sessionhostimage.vhd"
}
},
"storageAccountResourceGroupName": {
"type": "String",
"metadata": {
"description": "The storage account containing the custom VHD."
}
},
"vmGalleryImageOffer": {
"defaultValue": "",
"type": "String",
"metadata": {
"description": "(Required when vmImageType = Gallery) Gallery image Offer."
}
},
"vmGalleryImagePublisher": {
"defaultValue": "",
"type": "String",
"metadata": {
"description": "(Required when vmImageType = Gallery) Gallery image Publisher."
}
},
"vmGalleryImageSKU": {
"defaultValue": "",
"type": "String",
"metadata": {
"description": "(Required when vmImageType = Gallery) Gallery image SKU."
}
},
"rdshPrefix": {
"defaultValue": "[take(toLower(resourceGroup().name),10)]",
"type": "String",
"metadata": {
"description": "This prefix will be used in combination with the VM number to create the VM name. This value includes the dash, so if using “rdsh” as the prefix, VMs would be named “rdsh-0”, “rdsh-1”, etc. You should use a unique prefix to reduce name collisions in Active Directory."
}
},
"rdshNumberOfInstances": {
"type": "Int",
"metadata": {
"description": "Number of session hosts that will be created and added to the hostpool."
}
},
"rdshVMDiskType": {
"allowedValues": [
"Premium_LRS",
"StandardSSD_LRS",
"Standard_LRS"
],
"type": "String",
"metadata": {
"description": "The VM disk type for the VM: HDD or SSD."
}
},
"rdshVmSize": {
"defaultValue": "Standard_A2",
"type": "String",
"metadata": {
"description": "The size of the session host VMs."
}
},
"enableAcceleratedNetworking": {
"defaultValue": false,
"type": "Bool",
"metadata": {
"description": "Enables Accelerated Networking feature, notice that VM size must support it, this is supported in most of general purpose and compute-optimized instances with 2 or more vCPUs, on instances that supports hyperthreading it is required minimum of 4 vCPUs."
}
},
"administratorAccountUsername": {
"type": "String",
"metadata": {
"description": "The username for the domain admin."
}
},
"administratorAccountPassword": {
"type": "SecureString",
"metadata": {
"description": "The password that corresponds to the existing domain username."
}
},
"vmAdministratorAccountUsername": {
"defaultValue": "",
"type": "String",
"metadata": {
"description": "The virtual machine admin user name. The domain administrator username will be used if this parameter is not provided."
}
},
"vmAdministratorAccountPassword": {
"defaultValue": "",
"type": "SecureString",
"metadata": {
"description": "The virtual machine admin password. The domain administrator password will be used if this parameter is not provided."
}
},
"vhds": {
"type": "String",
"metadata": {
"description": "The URL to store unmanaged disks."
}
},
"subnet_id": {
"type": "String",
"metadata": {
"description": "The unique id of the subnet for the nics."
}
},
"rdshImageSourceId": {
"defaultValue": "",
"type": "String",
"metadata": {
"description": "Resource ID of the image."
}
},
"location": {
"defaultValue": "",
"type": "String",
"metadata": {
"description": "Location for all resources to be created in."
}
},
"createNetworkSecurityGroup": {
"defaultValue": false,
"type": "Bool",
"metadata": {
"description": "Whether to create a new network security group or use an existing one"
}
},
"networkSecurityGroupId": {
"defaultValue": "",
"type": "String",
"metadata": {
"description": "The resource id of an existing network security group"
}
},
"networkSecurityGroupRules": {
"defaultValue": {},
"type": "Array",
"metadata": {
"description": "The rules to be given to the new network security group"
}
},
"networkInterfaceTags": {
"defaultValue": {},
"type": "Object",
"metadata": {
"description": "The tags to be assigned to the network interfaces"
}
},
"networkSecurityGroupTags": {
"defaultValue": {},
"type": "Object",
"metadata": {
"description": "The tags to be assigned to the network security groups"
}
},
"virtualMachineTags": {
"defaultValue": {},
"type": "Object",
"metadata": {
"description": "The tags to be assigned to the virtual machines"
}
},
"imageTags": {
"defaultValue": {},
"type": "Object",
"metadata": {
"description": "The tags to be assigned to the images"
}
},
"vmInitialNumber": {
"defaultValue": 0,
"type": "Int",
"metadata": {
"description": "VM name prefix initial number."
}
},
"_guidValue": {
"defaultValue": "[newGuid()]",
"type": "String"
},
"hostpoolToken": {
"type": "SecureString",
"metadata": {
"description": "The token for adding VMs to the hostpool"
}
},
"hostpoolName": {
"type": "String",
"metadata": {
"description": "The name of the hostpool"
}
},
"hostpoolResourceGroup": {
"defaultValue": "",
"type": "String",
"metadata": {
"description": "The resource group of the host pool to be updated. Used when the host pool was created empty."
}
},
"hostpoolLocation": {
"defaultValue": "",
"type": "String",
"metadata": {
"description": "The location of the host pool to be updated. Used when the host pool was created empty."
}
},
"hostpoolProperties": {
"defaultValue": {},
"type": "Object",
"metadata": {
"description": "The properties of the Hostpool to be updated. Used when the host pool was created empty."
}
},
"ouPath": {
"defaultValue": "",
"type": "String",
"metadata": {
"description": "OUPath for the domain join"
}
},
"domain": {
"defaultValue": "",
"type": "String",
"metadata": {
"description": "Domain to join"
}
},
"apiVersion": {
"defaultValue": "2019-12-10-preview",
"type": "String",
"metadata": {
"description": "WVD api version"
}
}
},
"variables": {
"domain": "[if(equals(parameters('domain'), ''), last(split(parameters('administratorAccountUsername'), '@')), parameters('domain'))]",
"storageAccountType": "[parameters('rdshVMDiskType')]",
"isVMAdminAccountCredentialsProvided": "[and(not(equals(parameters('vmAdministratorAccountUsername'), '')), not(equals(parameters('vmAdministratorAccountPassword'), '')))]",
"vmAdministratorUsername": "[if(variables('isVMAdminAccountCredentialsProvided'), parameters('vmAdministratorAccountUsername'), first(split(parameters('administratorAccountUsername'), '@')))]",
"vmAdministratorPassword": "[if(variables('isVMAdminAccountCredentialsProvided'), parameters('vmAdministratorAccountPassword'), parameters('administratorAccountPassword'))]",
"copy": [
{
"name": "VMResourceIDs",
"count": "[parameters('rdshNumberOfInstances')]",
"input": {
"name": "[resourceId('Microsoft.Compute/virtualMachines', concat(parameters('rdshPrefix'), '-', add(copyIndex('VMResourceIDs'),parameters('vmInitialNumber'))))]"
}
}
]
},
"resources": [
{
"type": "Microsoft.Resources/deployments",
"apiVersion": "2018-05-01",
"name": "[concat('UpdateHostPool-', parameters('_guidValue'))]",
"properties": {
"mode": "Incremental",
"template": {
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"resources": [
{
"name": "[parameters('hostpoolName')]",
"apiVersion": "[parameters('apiVersion')]",
"location": "[parameters('hostpoolLocation')]",
"type": "Microsoft.DesktopVirtualization/hostpools",
"properties": "[parameters('hostpoolProperties')]"
}
]
}
},
"resourceGroup": "[parameters('hostpoolResourceGroup')]",
"condition": "[not(empty(parameters('hostpoolResourceGroup')))]"
},
{
"type": "Microsoft.Network/networkInterfaces",
"apiVersion": "2018-11-01",
"name": "[concat(parameters('rdshPrefix'),'-', add(copyindex(), parameters('vmInitialNumber')), '-nic')]",
"location": "[parameters('location')]",
"dependsOn": [
"[concat('UpdateHostPool-', parameters('_guidValue'))]"
],
"tags": "[parameters('networkInterfaceTags')]",
"properties": {
"ipConfigurations": [
{
"name": "ipconfig",
"properties": {
"privateIPAllocationMethod": "Dynamic",
"subnet": {
"id": "[parameters('subnet_id')]"
}
}
}
],
"enableAcceleratedNetworking": "[parameters('enableAcceleratedNetworking')]",
"networkSecurityGroup": "[if(empty(parameters('networkSecurityGroupId')), json('null'), json(concat('{\"id\": \"', variables('nsgId'), '\"}')))]"
},
"copy": {
"name": "rdsh-nic-loop",
"count": "[parameters('rdshNumberOfInstances')]"
}
},
{
"type": "Microsoft.Compute/virtualMachines",
"apiVersion": "2018-10-01",
"name": "[concat(parameters('rdshPrefix'),'-', add(copyindex(), parameters('vmInitialNumber')))]",
"location": "[parameters('location')]",
"dependsOn": [
"[concat('Microsoft.Network/networkInterfaces/', parameters('rdshPrefix'),'-',add(copyindex(), parameters('vmInitialNumber')), '-nic')]"
],
"tags": "[parameters('virtualMachineTags')]",
"properties": {
"hardwareProfile": {
"vmSize": "[parameters('rdshVmSize')]"
},
"availabilitySet": {
"id": "[resourceId('Microsoft.Compute/availabilitySets/', concat(parameters('rdshPrefix'),'-', 'availabilitySet-', parameters('location')))]"
},
"osProfile": {
"computerName": "[concat(parameters('rdshPrefix'),'-', add(copyindex(), parameters('vmInitialNumber')))]",
"adminUsername": "[variables('vmAdministratorUsername')]",
"adminPassword": "[variables('vmAdministratorPassword')]"
},
"storageProfile": {
"osDisk": {
"createOption": "FromImage",
"managedDisk": {
"storageAccountType": "[variables('storageAccountType')]"
}
},
"imageReference": {
"id": "[parameters('rdshImageSourceId')]"
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "[resourceId('Microsoft.Network/networkInterfaces',concat(parameters('rdshPrefix'),'-', add(copyindex(), parameters('vmInitialNumber')), '-nic'))]"
}
]
},
"diagnosticsProfile": {
"bootDiagnostics": {
"enabled": false
}
},
"licenseType": "Windows_Client"
},
"copy": {
"name": "rdsh-vm-loop",
"count": "[parameters('rdshNumberOfInstances')]"
}
},
{
"type": "Microsoft.Compute/virtualMachines/extensions",
"apiVersion": "2018-10-01",
"name": "[concat(parameters('rdshPrefix'),'-', add(copyindex(), parameters('vmInitialNumber')), '/', 'joindomain')]",
"location": "[parameters('location')]",
"dependsOn": [
"rdsh-vm-loop"
],
"properties": {
"publisher": "Microsoft.Compute",
"type": "JsonADDomainExtension",
"typeHandlerVersion": "1.3",
"autoUpgradeMinorVersion": true,
"settings": {
"name": "[variables('domain')]",
"ouPath": "[parameters('ouPath')]",
"user": "[parameters('administratorAccountUsername')]",
"restart": "true",
"options": "3"
},
"protectedSettings": {
"password": "[parameters('administratorAccountPassword')]"
}
},
"copy": {
"name": "rdsh-domain-join-loop",
"count": "[parameters('rdshNumberOfInstances')]"
}
},
{
"type": "Microsoft.Compute/virtualMachines/extensions",
"apiVersion": "2018-10-01",
"name": "[concat(parameters('rdshPrefix'),'-', add(copyindex(), parameters('vmInitialNumber')), '/', 'dscextension')]",
"location": "[parameters('location')]",
"dependsOn": [
"rdsh-domain-join-loop"
],
"properties": {
"publisher": "Microsoft.Powershell",
"type": "DSC",
"typeHandlerVersion": "2.73",
"autoUpgradeMinorVersion": true,
"settings": {
"modulesUrl": "[parameters('artifactsLocation')]",
"configurationFunction": "Configuration.ps1\\AddSessionHost",
"properties": {
"hostPoolName": "[parameters('hostpoolName')]",
"registrationInfoToken": "[parameters('hostpoolToken')]"
}
}
},
"copy": {
"name": "rdsh-dsc-loop",
"count": "[parameters('rdshNumberOfInstances')]"
}
}
],
"outputs": {
"resourceID": {
"type": "array",
"value": "[variables('VMResourceIDs')]"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment