You can use PowerCLI to get the uptime of all your ESXi hosts quickly and easily. This is done by retrieving the boot time data hidden away in the information retrieved by the get-vmhost
cmdlet.
Let’s take a look at some example code:
$date = get-date
Get-VMHost |Select Name, Parent, connectionstate, @{N="Last Boot (UTC)";E={$_.ExtensionData.Summary.Runtime.BootTime}},
@{N="Uptime (Days)"; E={New-Timespan -Start $_.ExtensionData.Summary.Runtime.BootTime -End $date | Select -ExpandProperty Days}} | ft -a
This results in the following output:
Name Parent ConnectionState Last Boot (UTC) Uptime (Days)
---- ------ --------------- --------------- -------------
DC0_H0 host Connected 09/06/2022 11:25:03 1
DC0_C0_H0 DC0_C0 Connected 09/06/2022 11:25:03 1
DC0_C0_H1 DC0_C0 Connected 09/06/2022 11:25:03 1
DC0_C0_H2 DC0_C0 Connected 09/06/2022 11:25:03 1
There you have it. A quick and easy way to get host uptime using PowerCLI.