VMware Cloud Community
Skagnola
Enthusiast
Enthusiast
Jump to solution

Pull list of VMs by Name, and sys.osuptime.latest

Hello

I am trying to pull a list of VMs with their Get-Stat for uptime and the VM name. I am having a little trouble getting these in a clean manner.

Below is what works fine for pulling a single VM uptime

Get-Stat -Entity testvm -Stat 'sys.osuptime.latest' -Realtime -MaxSamples 1 -ErrorAction SilentlyContinue | Select @{N='Uptime (d.hh:mm:ss)';E={[timespan]::FromSeconds($_.value)}}

But I would like to put a Get-Folder or Get-VM 'format of vm names' | <then the above code> to output to a more digestible format like Name | Uptime (d.hh:mm:ss) .

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Try something like this

$vms = Get-Folder -Name MyFolder | Get-VM

Get-Stat -Entity $vms -Stat 'sys.osuptime.latest' -Realtime -MaxSamples 1 -ErrorAction SilentlyContinue |

  Select @{N = 'VM'; E = {$_.Entity.Name}},

   @{N = 'Uptime (d.hh:mm:ss)'; E = {[timespan]::FromSeconds($_.value)}}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

2 Replies
LucD
Leadership
Leadership
Jump to solution

Try something like this

$vms = Get-Folder -Name MyFolder | Get-VM

Get-Stat -Entity $vms -Stat 'sys.osuptime.latest' -Realtime -MaxSamples 1 -ErrorAction SilentlyContinue |

  Select @{N = 'VM'; E = {$_.Entity.Name}},

   @{N = 'Uptime (d.hh:mm:ss)'; E = {[timespan]::FromSeconds($_.value)}}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Skagnola
Enthusiast
Enthusiast
Jump to solution

Luc! Thank you!

I was close; had my syntax order wrong. Appreciate the help!

0 Kudos