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
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.
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.
Thanks for the hint to the vmware.hv.helper module, that's a really good start!
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.
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])
}
}
Hello @Magneet
Can you share your opinion on this?
***Sorry for replying on different post
Thank you