SOLVED

Re assign user to Session host in Personal Pool desktop

Copper Contributor

Hi All,

Good Day!!!,

We deployed WVD Spring 2020 setup , we provisioned some set of Personal Pool-Personal Desktop and assigned to respective users into each sesionhost . Now the issue is we need to remove one user from assigned session and then add new user to the same sessionhost.

How can we achieve this, we tried to update using

Update-AzWvdSessionHost -HostPoolName HP01 -Name AZURE-WVD-5.domain.com -ResourceGroupName AZURE-WVD1-RSG -
AssignedUser:$false

but above command did not worked .

 

Any help will be appreciated 

 

Thanks & Regards,

Kesavan K M

6 Replies
best response confirmed by Kesavan Munuswamy (Copper Contributor)
Solution

@Kesavan Munuswamy  Hi, unfortunately you cannot re-assign a host to a user. The quickest way to do this is to delete the existing host and just add in another one. 

 

If you don't want to remove and re-deploy you can re-install the wvd broker agent on the VM using the following steps

 

1) Remove the host from the pool

2) RDP onto the VM and uninstall the WVD Broker Agent 

3) Generate a new token from the portal 

4) Re-install the agent using the token 

5) Assign the host to the user

 

Hope that helps! 

This worked for me.

1) Remove the host from the pool
2) Generate new token
3) HKLM\Software\Microsoft\RDInfraAgent --> Enter new token in "RegistrationToken"
4) HKLM\Software\Microsoft\RDInfraAgent --> Set "IsRegistered" to "0".

5) Reboot the session host

6) Assign the host to the user

It will probably work without reboot if you restart the correct services.


@EirikV 

Yes I have confirmed it works without a Reboot.
This gentleman's code helped me out
https://github.com/marcelin/AzureStartVmOnConnect/blob/20d841e936a8767d49e0da02c06e3b97657fc997/WVD/...

$strRoleDefinitionName = "Desktop Virtualization User"
$strResourceName = "appgrp-wvd-xxx-yyy-std-01"
$strResourceType = 'Microsoft.DesktopVirtualization/applicationGroups'
$strResourceGroupName = "rg-prd-xxx-yyy-001"
$SessionHostName = "WVDSessionHostName"
$SessionHostAdminCreds = Get-Credential

Set-AzContext -SubscriptionName Your-Subscription

$CommonParams = @{
    ResourceGroupName = $strResourceGroupName;
    HostPoolName      = "wvd-prd-xxx-yyy-001"
}

Write-Host "###... Removing role $strRoleDefinitionName for the user $User..."
Remove-AzRoleAssignment -SignInName $User -RoleDefinitionName $strRoleDefinitionName -ResourceName $strResourceName -ResourceGroupName $strResourceGroupName -ResourceType $strResourceType

Write-Host "###... Removing WVD Host $SessionHostName for the user $User..."
Remove-AzWvdSessionHost -Name $SessionHostName @CommonParams -Force


$RegInfo = New-AzWvdRegistrationInfo -ExpirationTime (Get-Date).AddDays(1) @CommonParams
Write-Host "###... Generated new registration token ... $RegInfo..."
    
Invoke-Command -ComputerName $SessionHostName -Credential $SessionHostAdminCreds -ScriptBlock {
    param($RegistrationToken)
    Write-Host "### Entered host $(hostname), starting adding back to the hostpool."
    Set-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\RDInfraAgent\ -Name IsRegistered -Value 0 -passthru
    Set-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\RDInfraAgent\ -Name RegistrationToken -Value $RegistrationToken -Passthru

    Write-Host "###... Changed registry values ..."
    #Not sure if this is required 
    Restart-Service RDAgent
    Write-Host "###... Restarted RDAgent service ..."
    #This kicked off the registration
    Start-service RDAgentBootLoader
    Write-Host "###... Restarted RDAgentBootLoader service ..."
} -ArgumentList $RegInfo.token


I have tested it and works like a charm. Whew! Thanks! 

Hi Eirikv, Good Day!!!, I was found this 2 registry Key value update would be the easy and fasted way to do the changes i was done bunch of instances with this way.

Thanks, by Kesavan K M

Hi @Neil McLoughlin 

Thanks for your answer, it's exactely what I was looking for.

I just have a question : how do you generate a new token ?

 

@PatrickBrechbiehl1966 

 

Azure Virtual Desktop --> Host Pools --> Your host pool --> Registration Key --> Generate new key

1 best response

Accepted Solutions
best response confirmed by Kesavan Munuswamy (Copper Contributor)
Solution

@Kesavan Munuswamy  Hi, unfortunately you cannot re-assign a host to a user. The quickest way to do this is to delete the existing host and just add in another one. 

 

If you don't want to remove and re-deploy you can re-install the wvd broker agent on the VM using the following steps

 

1) Remove the host from the pool

2) RDP onto the VM and uninstall the WVD Broker Agent 

3) Generate a new token from the portal 

4) Re-install the agent using the token 

5) Assign the host to the user

 

Hope that helps! 

View solution in original post