Before we proceed … when you post code, sample data, console output or error messages please format it as code using the preformatted text button ( </> ). Simply place your cursor on an empty line, click the button and paste your code.
The $hostpool variable is populated with the Hostpool name as a hash table. I then pull out the Name Key value to a string and store it in the $HostpooName Variable which I use to get the assigned virtual desktop user for the VM. $Assigned = get-AzWvdSessionHost -HostPoolName $hostpoolname -Name $vm -ResourceGroupName $group | Select AssignedUser
I get the error on the get-AzWVDsessionHost command because it doesn’t like the $hostpoolname variable. Not sure why. If I put the host pool name in the command directly it works fine.
If I put this hostpool name in the -hostpoolname parameter in the get-AzWvdSessionHost -HostPoolName $hostpoolname -Name $vm -ResourceGroupName $group | Select AssignedUser