Reassign a WVD Personal Session Host

 I get asked all the time "how do I re-assign a personal session host in WVD"?

The official answer is you don't. However, this can be easily achieved. The steps below are currently:

  • the quickest way to achieve this.
  • configured all in one place via the Azure portal, using a little used feature.
  • does not require a reboot.
These simple steps will get the registration token, remove the session host from the host pool, then update the registry with the required settings and force the re-registration of the session host with the WVD control plane, by restarting the specific responsible service.

If you have done anything with WVD to this point, you will be aware there are two types of host pools:
  • Pooled - designed for a multi-session OS and any user can login to any VM in the pool.
  • Personal - designed for a single session OS and the Session hosts are assigned, either automatically as a user connects or they can be directly assigned ahead of time. Once assigned that VM is dedicated to the assigned user and cannot be modified.
So why is this even a problem. Why can't you just natively re-assign a session host?

The reason for this is due to the expected use case. With Pooled host pools, you would deploy FSLogix to manage the user profile separately from the VM. This is what enables any user to connect to any VM and still have the same user experience, and there is nothing specific or dedicated about any VM for any user.

Personal however is a different use case. They are designed for when a user needs something specific on a VM that is not present on any other, this might be specific software. Or it might be that the user needs admin access, i.e., a developer who needs to install or uninstall software over time. Hence the VM becomes very personal. Just giving that VM to another user means they will inherit that VM's personalisation that the previous user had. 
Hence the expected process is that when a user of a personal VM no longer requires it, the VM is removed from the host pool and deleted. A new user will have a new personal VM created and assigned for them.

However, there will be times, maybe when testing, where it might be required or at least preferable from a time perspective to re-assign a VM to a different user. Whilst we don't surface a simple method to do just this via the WVD tooling, there is a simple task to achieve this.

There are three simple steps required to configure this, that can all be done in the one place - the Azure portal.

  1. Get or create the host pools registration token. 
  2. Remove the VM from the host pool. (if this is missed step 3 won't be effective)
  3. Run a script to re-register the session host VM with the host pool which removes the assigned user.
The thing that is different here than other posts for doing this is that the script is run from the Azure portal, giving us a simple way of doing this for any session host. For step 3 we will use a little-known feature of the Azure portal called the Virtual Machine "Run command". As we are running this script from the portal then we will do steps 1 and 2 in the same place to keep it simple and quick, (even though these steps can also be run via other tooling)

Step 1. Get or create a new host pool registration token.


We need the registration token later in step 3 when we re-register this session host with the host pool.
In the Windows Virtual Desktop hub section of the Azure portal, go to the host pool that this session host is a part of.  Click on Registration key:


If this registration key has not yet expired copy the entire key, ready for step 3.
If the key has expired you will need to click on Generate new key at the top, select a new expiration date and click on OK.


Now copy this new registration key.

Step 2. Remove session host from the host pool.


Navigate to your host pool that contains the session host you want to re-assign. In the Manage section go to Session hosts. In this case I want to remove my user, Chris from the Personal-1 session host:


Click on the name of the session host link in the first column, i.e. Personal-1...
This will take you to this specific session hosts blade.



Click on Remove session host at the top, and then Remove, but stay in the same blade when finished as we need to follow a link on this page and it also maintains the breadcrumb links at the top to make it quicker later.



The session host is now removed from the host pool:




Step 3. Use Run command to run a script to register session host. 


Click on the virtual machine name link in this blade, this takes us from the WVD hub to the Azure Virtual Machine blade for this session host.




Now you are looking at the standard Azure portal for this Virtual Machine object.
On the left-hand side in the Operations section at the bottom is the Run Command, click on this.


This feature allows you to run a number of different scripts targeted against this particular Virtual Machine. This uses the local VM agent to take and run the script within the VM itself.

The first option enables you to run a PowerShell script.


Click on RunPowerShellScript at the top of this list.
In the resulting Run Command Script enter these few lines of script:

    
Get-ItemProperty -Path Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\RDInfraAgent 

Set-ItemProperty -Path Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\RDInfraAgent -Name RegistrationToken -Value "<Reg Token>"

Set-ItemProperty -Path Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\RDInfraAgent -Name IsRegistered -Value 0 

Restart-Service -Name RDAgentBootLoader

Get-ItemProperty -Path Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\RDInfraAgent 


Now in line two replace the <Reg Token> text with your actual host pool registration token copied earlier.





Click on the Run button.
This will open an Output window, where shortly you will see the results of the script.

The script will enter the host pools registration token into the registry, it will then set the "IsRegistered" value that will force the WVD Boot loader agent to register this session host with the host pool. It will finish by restarting the WVD Boot loader agent which in turn does the registration:



In the breacrumb trail at the top click on the name of your host pool (you may need to refresh), you will see the existing VM is now back as a session host, registered and ready to be assigned to another user.



Comments

  1. Hi, it works only for Personal Hostpools? or Pooled can be works too ?

    ReplyDelete
    Replies
    1. Yes "assignment" is a feature on just personal host pools. "Pooled" host pools are for multi session OS's and thus can not be dedicated to any one person

      Delete
    2. Whilst user assignment is a feature of personal host pools, you can use this procedure as is on pooled host pools. This will allow you to remove a session host from a host pool and either re-add it back in again or move it to another host pool.

      Delete
  2. Easiest way of doing it. Thanks Tom for the wonderful content.

    ReplyDelete
  3. Thank you a lot, saved my day! I was stuck.

    ReplyDelete

Post a Comment

Popular posts from this blog

AVD and Azure Active Directory Domain Join public preview

How to deploy a Windows Virtual Desktop host pool using Infrastructure as code from Azure DevOps