Hi @Roger Roger ,
please try this script. I haven't tested the assignedUser
details because I have no Personal Session Hosts in my environment.
$rg = "<your resource group name>"
$hostPool = "<your host group name"
$outFile = "Sample7outputAvdVMs.txt"
$header = "Name,Status,assignedUser,subscription,resourceGroup,sku"
Out-File -FilePath $outfile -Encoding utf8 -InputObject $header
$output = ""
$sessionHosts = (Get-AzWvdSessionHost -ResourceGroupName $rg -HostPoolName $hostPool) # .ResourceId
$sessionHosts | ForEach-Object {
$vmName = ($_.ResourceId).Split("/")[-1]
$vmObj = (Get-AzVM -Name $vmName)
$vmStatus = (Get-AzVM -Name $vmName -Status).PowerState
$vmRG = $vmObj.ResourceGroupName
$vmSubscription = $vmObj.Id.Split("/")[2]
$vmSize = $vmObj.HardwareProfile.VmSize
$vmAssignedUser = $_.AssignedUser
$output = "$vmName,$vmStatus,$vmAssignedUser,$vmSubscription,$vmRG,$vmSize"
Out-File -FilePath $outfile -Encoding utf8 -InputObject $output -Append
}
The result looks here like this (as I mentioned before I have no personal Session Hosts in my environment):
Name,Status,assignedUser,subscription,sku
WVD-pHost-0,VM deallocated,,<subscription id>,<name of VM Resource Group>,Standard_B2ms
WVD-pHost-1,VM deallocated,,<subscription id>,<name of VM Resource Group>,Standard_B2ms
(If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)
Regards Andreas Baumgarten