VMware Horizon Community
doppelgrau
Contributor
Contributor
Jump to solution

Get vm-status for horizon view desktop-pools

Hi,

is there a away to get the vm-state (available, connected, agend needs reboot and so on) (remote) with powershell oder an other usable api?

I tried it today, but found no examples and in the API documentation I found some calls that looked like they might help, but that lead to nothing.

greetings

Johannes

0 Kudos
1 Solution

Accepted Solutions
Magneet
Hot Shot
Hot Shot
Jump to solution

try the vmware.hv.helper module from the example scripts GitHub - vmware/PowerCLI-Example-Scripts  get-hvpool or get-hvmachinesummary is what you need. From my post about the vCheck for Horizon here you might get some ideas for more stuff.

for example

(get-hvmachinesummary | where {$_.base.basicstate -eq "AVAILABLE"}).count

will give a count for all available desktops.

View solution in original post

0 Kudos
5 Replies
Magneet
Hot Shot
Hot Shot
Jump to solution

try the vmware.hv.helper module from the example scripts GitHub - vmware/PowerCLI-Example-Scripts  get-hvpool or get-hvmachinesummary is what you need. From my post about the vCheck for Horizon here you might get some ideas for more stuff.

for example

(get-hvmachinesummary | where {$_.base.basicstate -eq "AVAILABLE"}).count

will give a count for all available desktops.

0 Kudos
doppelgrau
Contributor
Contributor
Jump to solution

Thanks for the hint to the vmware.hv.helper module, that's a really good start!

0 Kudos
Magneet
Hot Shot
Hot Shot
Jump to solution

if you are looking for more cmdlets that aren't in there yet open an issue on github or contact me, I might be able to add it for you.

0 Kudos
doppelgrau
Contributor
Contributor
Jump to solution

Thanks. Might come back to you, but for today I'm quite happy with the result:

Import-Module VMware.VimAutomation.HorizonView

Import-Module VMware.VimAutomation.Core

Get-Module -ListAvailable 'VMware.Hv.Helper' | Import-Module

$connection = Connect-HVServer -server host

$pools = @{}

$vms = get-hvmachinesummary

foreach ($vm in $vms) {

    $desktoppool = $vm.NamesData.DesktopName

    $state = $vm.Base.BasicState

    $states = @{AVAILABLE = 0;CONNECTED = 0}

    if( $pools.ContainsKey($desktoppool) ){

        $states = $pools.Get_Item($desktoppool)

    }

    else{

        $pools.Add($desktoppool, $states)

    }

    if( $states.ContainsKey($state) ){

        $states[$state] = $states[$state] + 1

    }

    else{

        $states.Add($state,1)

    }

}

Write-Output "# HELP vmware_horizonView_desktoppool_vms_total Number of vms for a dekstoppool in each state"

Write-Output "# TYPE vmware_horizonView_desktoppool_vms_total gauge"

foreach ( $pool in $pools.Keys ) {

    $states = $pools[$pool]

    foreach ( $state in $states.Keys ) {

        Write-Output  ("vmware_horizonView_desktoppool_vms_total{pool=`"" + $pool + "`", state=`"" + $state + "`",} " + $states[$state])

    }

}

g9panas
Contributor
Contributor
Jump to solution

Hello @Magneet 
Can you share your opinion on this?

https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Recompose-Horizon-Desktop-Pools-via-Po...

***Sorry for replying on different post

Thank you

0 Kudos