Export Last heartbeat time of session host in host pools

Yasar Shaikh 40 Reputation points
2024-09-23T15:30:10.6433333+00:00

I need to export Last heartbeat time of each and every session host in host pools . Please suggest what are the ways to do it please share the working query for azure graph resource or log analytics or powershell script & CLI script or any way to export from portal . Please help

Azure Virtual Desktop
Azure Virtual Desktop
A Microsoft desktop and app virtualization service that runs on Azure. Previously known as Windows Virtual Desktop.
1,527 questions
{count} votes

1 answer

Sort by: Most helpful
  1. hossein jalilian 6,830 Reputation points
    2024-09-23T16:39:57.2133333+00:00

    Thanks for posting your question in the Microsoft Q&A forum.

    You have several options:

    PowerShell Script:

    # Connect to Azure (if not already connected)
    Connect-AzAccount
    
    # Get all host pools
    $hostPools = Get-AzWvdHostPool
    
    # Initialize an array to store results
    $results = @()
    
    foreach ($hostPool in $hostPools) {
        $sessionHosts = Get-AzWvdSessionHost -HostPoolName $hostPool.Name -ResourceGroupName $hostPool.ResourceGroupName
    
        foreach ($sessionHost in $sessionHosts) {
            $results += [PSCustomObject]@{
                HostPoolName = $hostPool.Name
                SessionHostName = $sessionHost.Name.Split('/')[-1]
                LastHeartbeat = $sessionHost.LastHeartBeat
                Status = $sessionHost.Status
            }
        }
    }
    
    # Export results to CSV
    $results | Export-Csv -Path "SessionHostHeartbeats.csv" -NoTypeInformation
    
    

    Azure CLI:

    You can use the Azure CLI to retrieve similar information.

    Azure Portal:

    You can view the Last heartbeat time for session hosts, in Azure Virtual Desktop blade select Host pools for specific host pool go to the Session hosts tab

    Azure Resource Graph:

    You can use Azure Resource Graph to query this information.


    Please don't forget to close up the thread here by upvoting and accept it as an answer if it is helpful

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.