Error on get-AzWvdSessionHost Expected literal (number, boolean, or null). Was '<'


I am somewhat of a newbie with powershell. I am getting the errror Expected literal (number, boolean, or null). Was ‘<’.

For the following code.

group =
$vm =

$hostpool = Get-AzWvdHostPool -ResourceGroupName $group | Select-object Name
$HostpoolName = $hostpool | Select-Object -ExpandProperty Name | Out-String

$Assigned = get-AzWvdSessionHost -HostPoolName $hostpoolname -Name $vm -ResourceGroupName $group | Select AssignedUser

It errors on the -HostPoolName and I cannot find the solution.

Hopefully someone can help me.


Welcome to the forum. :wave:t4:

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.

Thanks in advance

How to format code in <---- Click :point_up_2:t4: :wink:

When you get errors you should post them here completely formatted as code.

I’d start with looking for the cause before I think about a solution. :wink:

Since you use a variable to provide a value … what’s in the variable $hostpoolname?

Here is the code

$group = "rg-agitprd01-avdext-017" 
$vm = "vdagitprd17-0.altus.local"

$hostpool = Get-AzWvdHostPool  -ResourceGroupName $group | Select-object Name 
$HostpoolName = $hostpool | Select-Object -ExpandProperty Name | Out-String

$Assigned = get-AzWvdSessionHost -HostPoolName $hostpoolname -Name $vm -ResourceGroupName $group | Select AssignedUser

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.

Thank You

Output for the $hostpool = Get-AzWvdHostPool -ResourceGroupName $group | Select-object Name command is

S C:\WINDOWS\system32> $hostpool



PS C:\WINDOWS\system32>

Output for the $HostpoolName = $hostpool | Select-Object -ExpandProperty Name | Out-String command is

PS C:\WINDOWS\system32> $HostpoolName

PS C:\WINDOWS\system32>

If I put this hostpool name in the -hostpoolname parameter in the get-AzWvdSessionHost -HostPoolName $hostpoolname -Name $vm -ResourceGroupName $group | Select AssignedUser

for instance

get-AzWvdSessionHost -HostPoolName hstpool-agitprd01-cace-017 -Name $vm -ResourceGroupName $group | Select AssignedUser

I get the correct output of the assigned user for the $vm

How do you manage to get the formatting mostly right in one post and mess it up completely in the next one? :man_shrugging:t4: :wink: And where is the error message?


When I read the help for the cmdlet Get-AzWvdSessionHost

I can see the expected [TYPE] for the parameter -HostPoolName is [STRING] !? :point_up_2:t4:

Without having experiences or even access to Azure to test I’d expect something like this to be enough:

$group = "rg-agitprd01-avdext-017" 
$vm = "vdagitprd17-0.altus.local"

$HostpoolName = 
    Get-AzWvdHostPool  -ResourceGroupName $group | 
        Select-Object -ExpandProperty Name
$Assigned = 
    get-AzWvdSessionHost -HostPoolName $hostpoolname -Name $vm -ResourceGroupName $group |
         Select-Object -Property AssignedUser

And please … when you post code OR console output OR error message - format it as code.


That worked! Thank You so much Sorry about the formatting new to posting on this forum.