powershellazure-avd

How to display Azure Virtual Desktop host properties instead of serial object?


I'm trying to figure out how to view the properties of Azure AVD session hosts via script. Instead, all I'm getting is a serialized object. How do I get it to output the properties? I've tried Format-List, but that has no effect.

$resourceGroup = "Group1"

$hostPoolObjects = Get-AzWvdHostPool -ResourceGroupName $resourceGroup

    foreach ($hostPool in $hostPoolObjects) {

        $sessionHosts = Get-AzWvdSessionHost -HostPoolName $hostPool.Name -ResourceGroupName $resourceGroup

        foreach ($sessionHost in $sessionHosts) {
            Write-Host $sessionHost
        }
    }
}

Output:

Microsoft.Azure.PowerShell.Cmdlets.DesktopVirtualization.Models.Api202209.SessionHost
Microsoft.Azure.PowerShell.Cmdlets.DesktopVirtualization.Models.Api202209.SessionHost
Microsoft.Azure.PowerShell.Cmdlets.DesktopVirtualization.Models.Api202209.SessionHost
Microsoft.Azure.PowerShell.Cmdlets.DesktopVirtualization.Models.Api202209.SessionHost
Microsoft.Azure.PowerShell.Cmdlets.DesktopVirtualization.Models.Api202209.SessionHost
Microsoft.Azure.PowerShell.Cmdlets.DesktopVirtualization.Models.Api202209.SessionHost
...

What am I missing in the code?


Solution

  • The following general advice applies:


    Therefore, the idiomatic reformulation of your code is the following, using pipeline-based parameter binding and relying on the pipeline's auto-enumeration behavior:

    Get-AzWvdHostPool -ResourceGroupName Group1 | Get-AzWvdSessionHost
    

    The Get-AzWvdSessionHost cmdlet's output objects determine the particular shape of the for-display representations, either by virtue of predefined formatting data associated with their type or, in its absence, whether the output objects have 4 or fever (public) properties (in which case Format-Table is implicitly used) or more (in which case Format-List is used).

    Either way, you're free to pipe to the various Format-* cmdlets to modify the default for-display representation, but note that using these cmdlets is only ever appropriate for display formatting, not for outputting data.