Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## Get session host and underlying VM details for all AVD host pools in scope (use Connect-AzAccount / Set-AzContext to change
- ## Written after user could not connect to AVD as Azure showed they had a session but the VM for that session host did not exist
- get-azwvdhostpool -PipelineVariable hp |ForEach-Object { $shost = $null ; $shosts = @( Get-AzWvdSessionHost -HostPoolName $hp.Name -ResourceGroupName $hp.ResourceGroupName ) ;if( $null -eq $shosts -or $shosts.Count -eq 0 ) { Write-Warning "Host pool $($hp.Name) has no session hosts!" } else { $shosts | % { $shost = $_ ; $vm = $null ; $vm = Get-AZVM -ResourceId $shost.ResourceId -EA 0; $shost | select @{n='HostPool';e={$hp.Name}},@{n='Name';e={Split-Path $shost.Name -leaf}},ResourceGroupName,@{n='VM Exists';e={ $null -ne $vm -and $vm.Id -eq $Shost.ResourceId }},AllowNewSession,AssignedUser,AgentVersion,Status,Session,@{n='Location';e={$vm.Location}},@{n='ProvisioningState';e={$vm.ProvisioningState}},@{n='StatusCode';e={$vm.statuscode}},@{n='ImageGallery';e={$vm.StorageProfile.ImageReference.id -replace '^.*/galleries/([^/]+)/.*$' , '$1'}},@{n='Image';e={$vm.StorageProfile.ImageReference.id -replace '^.*/images/([^/]+)/.*$' , '$1'}},@{n='ImageVersion';e={$vm.StorageProfile.ImageReference.ExactVersion}},@{n='VMCreated';e={$vm.TimeCreated}},@{n='Size';e={$vm.HardwareProfile.VmSize}}}}}
Advertisement