.

 

 

Windows Virtual Desktop - WVDHostBuilder

Download createWVDvm.ps1

Download deleteWVDvm.ps1

WVDHostBuilder is a powershell script that deploys Azure Windows Virtual Desktop Session Hosts using Ephemeral OS disks for Azure VMs.

WVDHostBuilder can deploy a single Azure virtual machine or multiple Azure virtual machines concurrently (up to twenty).

Virtual Machines running Windows 10 Enterprise multi-session may be deployed from Azure Gallery images or a Custom Managed Image.

The following tasks are performed during deployment:

  • Create one or more virtual machines and attach to a Virtual Network / Virtual Subnet
  • Join Active Directory Domain
  • Install Remote Desktop Services Infrastructure Agent & Remote Desktop Agent Boot Loader
  • Join Windows Virtual Desktop Host Pool and Availability set
  • Enable 'Drain mode' on the new Session Host to prevent user logons
  • Install FSlogix Agent (Optional)
  • Install Microsoft Teams and the WVD redirector (Optional)
  • Install Microsoft Operations Manager Agent - Logging & Analytics (Optional)
  • Disable 'Drain mode' on the new Session Host to enable user logons
Deployment from Windows Gallery Image Deployment from Custom Image which includes FSLogix and Teams

Both deployments above contain Office 365, OneDrive and Teams.

The Deployment from a custom image is signifcantly faster as FSLogix and Teams do not have to be deployed as they are already contained in the image. Deployment from a custom image is preferable as the deployed image should contain multiple applications beyond Office 365 and Teams .

The Custom Image above was deployed from a Standard HDD storage account. The VM Creation duration was 4 mins 38 secs. When deploying from a Premium SSD storage account. The VM Creation duration was 4 mins 8 secs.

When the same Custom Image was deployed from a Premium SSD Managed disk image, the VM Creation duration was 6 mins 40 secs!!!!!

 

Pre-Requisites

  • Azure PowerShell Module (Az.Compute)
  • Azure Subscription
  • Azure Resource Group
  • Azure Virtual Network
  • Azure Virtual Subnet
  • Windows Virtual Desktops Resource Provider
  • Pre-created WVD Host Pool
  • Pre-created Availability Set (Optional)
  • Azure Log Analytics Workspace (Optional)
  • Subscriber permission to all in-scope Azure Resources
  • Microsoft Active Directory Domain (Azure Virtual network DNS configured for Active Directory)
  • Active Directory user account with permission to join machines to the domain
  • Pre-created Organisational Unit
  • CreateWVDvm.ps1

The virtual machine being deployed requires internet access to the following URLs to download the required latest agents during deployment.

Remote Desktop Services Infrastructure Agent https://query.prod.cms.rt.microsoft.com/cms/api/am/binary/RWrmXv
Remote Desktop Agent Boot Loader https://query.prod.cms.rt.microsoft.com/cms/api/am/binary/RWrxrH
Microsoft FSLogix Agent https://aka.ms/fslogix_download
Microsoft Teams https://teams.microsoft.com/downloads/
Remote Desktop WebRTC Redirector Service https://query.prod.cms.rt.microsoft.com/cms/api/am/binary/RE4AQBt
Microsoft Monitoring Agent https://go.microsoft.com/fwlink/?LinkId=828603

Configure Parameters

All parameters may be passed via the command line, however it is simpler to configure common parameters in createWVDvm.ps1 for Sessions Hosts in the same host pool so that only the VMName parameter needs to passed via the command line.

e.g. .\CreateWVDvm.ps1 "NPWVD001"

Parameter Description

[String]$VMName= "VMName"
[String]$ResourceGroup= "Virtual_Machine_Resource_Group"
[String]$location= "westeurope"
[String]$vmSize= "Standard_DS3_v2"
[String]$AVSet= "N"
[String]$networkName= "Virtual_Network_Name"
[String]$subnetName= "Virtual_Subnet"
[String]$CustomImage= "N"
[String]$CustomSourceImage= "W10Multi2004_Feb142021"
[String]$publisherName= "microsoftwindowsdesktop"
[String]$offer= "office-365"
[String]$skus= "20h1-evd-o365pp"
[String]$LicType= "Windows_Client"
[String]$LocalAdmin= "LocAdmin"
[String]$LocalPW= "Complex_P@55w0rd!!!"
[String]$JoinDomain= "Y"
[String]$ADDomain= "domain.local"
[String]$OU= "ou=WVD,ou=Services,dc=domain,dc=local"
[String]$ADAdmin= "adminuser@domain.local"
[String]$ADAdminPW= "Complex_P@55w0rd!!!"
[String]$JoinHostPool= "N"
[String]$HostPool= "Host_Pool_Name"
[String]$HostPoolResourceGroup= "Host_Pool_Resource_Group"
[String]$InstallFSLogix= "Y"
[String]$InstallTeams= "Y"

[String]$InstallLA= "N"
[String]$LAWSID= '"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"'
[String]$LAWSKEY= '"QQQQQQQQQQQQQQQQQQQQQQQQQQQ=="'

# Set the New VM Name
# Set the Target Resource Group for the VM - Get-AzResourceGroup | select ResourceGroupName
# Set the Target Azure Location for the VM -- Get-AzLocation | select Location
# Set the VM Size -- Get-AzVMSize -Location $Location | select Name
# Set the ARM (not Classic) Availability set name - Type "N" if no AVset is used
# Set the Virtual Network Name
# Set the Virtual Subnet Name
# Use a custom image Y or use an Azure Gallery Image N
# If using a custom image
# If using a Gallery Image
# If using a Gallery Image
# If using a Gallery Image
# Set the License Type - W10=Windows_Client Server=Windows_Server
# Set the name of the local administrator account
# Set the password for the local administrator account
# Join a domain Y or N
# Set the domain name in FQDN format
# Set the Organisational Unit for the VM
# Set the domain join user account
# Set the domain join user account password
# Join a WVD HostPool - HostPool must have been precreated
# Set the WVD HostPool name
# Set the WVD HostPool Resource Group name
# Install FSLogix Y or N
# InstallTeams = "N" # Install Microsoft Teams Y or N
# Install Log Analytics Y or N
# Specify the Log analytics Workspace ID
# Specify the Log analytics Workspace Key

Notes:

The VM Cache size must be larger than the VM image, therefore the minimum recommended $vmSize is Standard_DS3_v2.

If using a custom image, the image and the associated disk must be in the same Azure Region as the Virual Machine being deployed.

Deploy a single WVD Session Host

Ensure that the pre-requisites have been fulfilled.

Configure environment specific parameters.

Run the following command:

.\createWVDvm.ps1 "VMNAME"

If you are not authenticated to Azure, the script will invoke Connect-AzAccount, therefore it is suggested that you manually run Connect-AzAccount before deploying any virtual machines.

Deploy Multiple WVD Session Hosts

Ensure that the pre-requisites have been fulfilled.

Configure parameters and deploy a single Virtual Machine to validate your configuration.

Multiple Virtual machines may be deployed concurrently using the start-job powershell cmdlet.

Create a parent powershell script, or run the following comands:

$NPWVD001=Start-Job -Name "NPWVD001" -FilePath .\createWVDvm.ps1 -ArgumentList "NPWVD001"
$NPWVD002=Start-Job -Name "NPWVD002" -FilePath .\createWVDvm.ps1 -ArgumentList "NPWVD002"
$NPWVD003=Start-Job -Name "NPWVD003" -FilePath .\createWVDvm.ps1 -ArgumentList "NPWVD003"
etc etc etc

If you are not authenticated to Azure, the script will invoke Connect-AzAccount, therefore it is suggested that you manually run Connect-AzAccount before deploying any virtual machines.

You can view the status of each job using the get-job powershell cmdlet

You can view a detailed status of each job using the receive-job powershell cmdlet

receive-job -Job $NPWVD001 -keep

Delete WVD Session Host(s)

If you want to update your WVDs to a new image version, you must first delete the existing Virtual Machines and redeploy them using a new updated image .

Download deleteWVDvm.ps1

deleteWVDvm.ps1 can remove the Virtual Machine from the WVD hostpool (as long as there are no active sessions), delete the Virtual Machine, delete it's NIC, delete the Azure AD Device (if it exists), and finally delete the Active Directory computer account.

Pre-Requisites

Configure Parameters

All parameters may be passed via the command line, however it is simpler to configure common parameters in deleteWVDvm.ps1 for Sessions Hosts in the same host pool so that only the VMName parameter needs to passed via the command line.

e.g. .\deleteWVDvm.ps1 "NPWVDHost001"

Parameter Description

[String]$VMName= "VMName"
[String]$RemoveWVD="Y"
[String]$HostPool="HostPool_Name"
[String]$HostPoolResourceGroup="HostPool_ResourceGroup"
[String]$ADDomain="domain.local"
[String]$DelAzureVM="Y"
[String]$DelAzureADDevice="Y"
[String]$DelADComputer="Y"

# Set the VM Name
# Remove Virtual Machine from WVD Host Pool
# Set the WVD HostPool name
# Set the WVD HostPool Resource Group name
# Set the Active Directory Domain Name
# Delete Azure Virtual Machine
# Delete Azure AD Device
# Delete Active Directory Computer Account

Run the following command:

.\deleteWVDvm.ps1 "VMNAME"

If you are not authenticated to Azure, the script will invoke Connect-AzAccount, therefore it is suggested that you manually run Connect-AzAccount before deleting any virtual machines.

If you are not authenticated to AzureAD, the script will invoke Connect-AzureAD, therefore it is suggested that you manually run Connect-AzureAD before deleting any virtual machines.

You can delete multiple Virtual Machines simultaneously with the following commands:

$NPWVD001=Start-Job -Name "NPWVD001" -FilePath .\deleteWVDvm.ps1 -ArgumentList "NPWVD001"
$NPWVD002=Start-Job -Name "NPWVD002" -FilePath .\deleteWVDvm.ps1 -ArgumentList "NPWVD002"

 

Known Issues:

After a successful deployment, a Session Host may show as 'Unavailable' in the WVD Host Pool.

This is because the 'Remote Desktop Agent Loader' Service has failed to start.

If you attempt to start the service manually the following error is displayed. Error 14001: Windows could not start the Remote Desktop Agent Loader service on Local Computer.

This is because the following file is empty: C:\Program Files\Microsoft RDInfra\RDAgentBootLoader\RDAgentBootLoader.exe.config

Update RDAgentBootLoader.exe.config with the following text.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2" />
</startup>
</configuration>

 

Related Articles :

Ephemeral OS disks for Azure VMs

Windows 10 Enterprise multi-session FAQ

Windows Virtual Desktop documentation

Create a Windows Virtual Desktop host pool

Optimizing Windows 10, version 2004 for a Virtual Desktop Infrastructure (VDI) role

Create a managed image of a generalized VM in Azure

Prepare and customize a master (Session-Host) VHD image

Device identity and desktop virtualization

Troubleshoot common Windows Virtual Desktop Agent issues

Use Log Analytics for the diagnostics feature