Hi guys, is there a way to get uptime info for all VMs in a cluster?
Basically a list with VM name, and uptime.
Thanks!
Sure, like this
Get-Cluster <cluster-name> | Get-VM | `
where {$_.PowerState -eq "PoweredOn"} | `
Get-Stat -Stat sys.uptime.latest -MaxSamples 1 -Realtime | `
select Entity,
@{Name="Boottime";
Expression={(Get-Date).AddSeconds(- $_.value).ToString("yy/MM/dd HH:mm:ss")}} | `
Export-Csv "C:\vm-bootime.csv" -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
There are several ways you can do this.
1) With the Get-Stat cmdlet
$clusterName = "MyCluster"
$vms = Get-Cluster -Name $clusterName | Get-VM
Get-Stat -Start (Get-Date) -Entity $vms -Stat sys.uptime.latest -MaxSamples 1 | `
Select @{N="VM";E={$_.Entity.Name}},
@{N="Uptime";E={New-TimeSpan -Seconds $_.Value}}
2) Using the BootTime property
$clusterName = "MyCluster"
$now = Get-Date
Get-Cluster -Name $clusterName | Get-VM | where {$_.PowerState -eq "PoweredOn"} |`
Select @{N="VM";E={$_.Name}}, @{N="Uptime";E={New-TimeSpan -Start $_.Extensiondata.Runtime.BootTime.ToLocalTime() -End $now}}
Unfortunately the BootTime property doesn't always seem to be populated.
I prefer the Get-Stat method.
Note that the Uptime is displayed in the default TimeSpan format: days.hours:minutes:seconds.ticks
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi LucD, thanks for the info.
When I run the Get-Stat method i get this:
Unexpected token 'vms' in expression or statement.
At :line:2 char:27
+ $clusterName = "ClusterA" $vms <<<< = Get-Cluster -Name $clusterName | Get-VM
Am I missing something?
vSphere 4.1 and PowerCLI 4.1.1
There was a problem with <CR><LF> when I copied the lines.
It's corrected, please try again.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I tried this other code you provided in another thread:
http://communities.vmware.com/message/1304574
Get-Cluster <cluster-name> | Get-VM | ` where {$_.PowerState -eq "PoweredOn"} | ` Get-Stat -Stat sys.uptime.latest -MaxSamples 1 -Realtime | ` select Entity, @{Name="Boottime"; Expression={(Get-Date).AddSeconds(- $_.value).ToString("yy/MM/dd HH:mm:ss")}}
It gets the job done, any way to get the info to an Excel sheet?
Thanks!
Sure, like this
Get-Cluster <cluster-name> | Get-VM | `
where {$_.PowerState -eq "PoweredOn"} | `
Get-Stat -Stat sys.uptime.latest -MaxSamples 1 -Realtime | `
select Entity,
@{Name="Boottime";
Expression={(Get-Date).AddSeconds(- $_.value).ToString("yy/MM/dd HH:mm:ss")}} | `
Export-Csv "C:\vm-bootime.csv" -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I now get:
The term ' ' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At :line:5 char:83
+ Get-Cluster -Name $clusterName | Get-VM | where {$_.PowerState -eq "PoweredOn"} |` <<<<
Awesome! thanks.
hi
is it possible to have this uptime on this year on % ?
tks advance
it's like this script
$esx = Get-VMHost 192.168.1.33
Get-VIEvent -Entity $esx -MaxSamples 99999 -Start (Get-Date).AddDays(-350) | `
where {"HostConnectionLostEvent","HostConnectedEvent" -contains $_.GetType().Name} | `
Sort-Object -Property {$_.CreatedTime.DateTime} -Unique | `
Select @{N="Hostname";E={$_.Host.Name}},
@{N="Time";E={$_.CreatedTime.ToShortDateString() + " " + $_.CreatedTime.ToShortTimeString()}},
@{N="Status";E={if($_.GetType().Name -eq "HostConnectedEvent"){"Connected"}else{"Not connected"}}} | Export-Csv c:\Temp\statsexportruntime.csv
but not for esx but vm and not all date like that but in % of down date :smileydevil:
With the events you will only be using poweron and poweroff events to determine the uptime.
Is that what you want to measure for uptime ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
with that i can only count downtime of esx server. since yesterday i try to calculate in % of time the downtime of esx but i don't found how.
Hi Luc
I try with your date script to export this value to csv file... but i have nothing on my csv....blank. do you know why ?
tks advance
Sorry i found How
Hello Dears
i have the same question, but this script only show UP time on VM layer, if the VM rebooted from OS layer is not detected, please is there any way to show uptime even if it is rebooted on OS layer?
You will have to do that query inside the Guest OS.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks a lot, but i am not OS administrator, i am managing only VMware layers and i was searching a lot to find away but till now no luck..
You can eventually look at the VMGuestRebootEvent and VMGuestShutdownEvent, that might give you some idea of the Guest OS uptime.
But in my experience there are too many special cases where this will not work.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
use something like ControlUp
Really?
Did you read the VMTN Community Code of Conduct, especially section Spam and shameless commerce
Since you are working for that company, at least some disclosure would be appreciated
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference