Forum Discussion

Lancelotbaghel30's avatar
Lancelotbaghel30
Copper Contributor
Dec 23, 2024

How we can create SessionHost in Azure Virtual Desktop using Azure Powershell?

Hi I am having one requirement where I need to create SessionHost VMs using Command Line , I followed references on Az.DesktopVirtualization Module where we have Cmdlet like New-AzWVDHostPool. 

Do we have similar cmdlet to create SessionHost as well?

 

Kindly help

  • Try this:

     

    1. Create the Virtual Machines: You can use the New-AzVM cmdlet to create the VMs. Here’s a basic example:
      $vmConfig = New-AzVMConfig -VMName "SessionHostVM" -VMSize "Standard_D2s_v3"
      $vm = New-AzVM -ResourceGroupName "YourResourceGroup" -Location "YourLocation" -VM $vmConfig

       

    2. Generate a Registration Key: You need a registration key to register the VMs as session hosts. Use the New-AzWVDRegistrationInfo cmdlet:
      $registrationInfo = New-AzWVDRegistrationInfo -ResourceGroupName "YourResourceGroup" -HostPoolName "YourHostPool"
      $registrationToken = $registrationInfo.Token

       

    3. Install the Azure Virtual Desktop Agent: On each VM, install the Azure Virtual Desktop Agent and register the VM using the registration token. This can be done via a script executed on the VM:
      Invoke-WebRequest -Uri "https://aka.ms/wvd/agent" -OutFile "C:\WVD\InstallAgent.ps1"
      Invoke-WebRequest -Uri "https://aka.ms/wvd/agentbootloader" -OutFile "C:\WVD\InstallBootloader.ps1"
      & "C:\WVD\InstallAgent.ps1"
      & "C:\WVD\InstallBootloader.ps1"
      & "C:\Program Files\Microsoft RDInfra\WVD\Agent\RDAgentBootLoader.exe" $registrationToken

       

    4. Verify the Session Hosts: Use the Get-AzWvdSessionHost cmdlet to verify that the VMs have been registered as session hosts:
      Get-AzWvdSessionHost -ResourceGroupName "YourResourceGroup" -HostPoolName "YourHostPool"

       

Resources