Jun 05 2020 02:19 PM
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
Jun 05 2020 10:17 PM
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!
Jun 25 2020 06:07 AM - edited Jun 25 2020 06:17 AM
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.
Jun 28 2021 02:54 AM
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!
Jun 28 2021 11:23 AM
Oct 28 2021 11:41 PM
Hi @virtualmanc
Thanks for your answer, it's exactely what I was looking for.
I just have a question : how do you generate a new token ?
Nov 02 2021 11:35 AM
Azure Virtual Desktop --> Host Pools --> Your host pool --> Registration Key --> Generate new key
Jun 05 2020 10:17 PM
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!