Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Get uptime for multiple VMs

Posted on 2010-11-26
5
Medium Priority
?
1,776 Views
Last Modified: 2012-05-10
Hi experts

I need to get a list of all powered on VMs and their current uptime. I thought this was trivial, but I havent been able to find a solution yet. Have spent some time with Google...

Hope someone can help

I have this, and need to add uptime:
get-vm | where {$_.PowerState -eq "PoweredOn"} | select Name, PowerState, Host

Open in new window

0
Comment
Question by:Bogeholm
  • 2
5 Comments
 
LVL 5

Expert Comment

by:Blake_1
ID: 34220865
You can achieve this by using PowerCLI to return the state of the servers and WMI to query the Operating System uptime (assuming this is the figure that you're after).

NB I haven't tested this script so the syntax may be wrong or it may not even work at all.  But it should put you on the right track.
get-vm | where { $_.PowerState -eq "PoweredOn" } | % { $objUptime = (Get-WmiObject -computer $_.Name -class Win32_PerfFormattedData_PerfOS_System).SystemUpTime ; $_ | select Name,PowerState,@{Name="Uptime";Expression={$objUptime}} }

Open in new window

0
 
LVL 3

Author Comment

by:Bogeholm
ID: 34222776
Thank you Blake1,

Could be an option, but my vCenter is not allowed to access the production network (virtuel machine network).
So I will not be able to use a WMI query against the VM. At the moment i execute the PS from the vCenter server - I do not have other options at the moment.
That is why I hope to do the job strictly in the vmware environment.

I'm reading the below from vmware communities, and have thus moved a bit closer to a solution:
http://communities.vmware.com/message/1304549

But instead of the Boottime I need the uptime (prefer counted in days)
0
 
LVL 5

Accepted Solution

by:
Blake_1 earned 2000 total points
ID: 34223908
You can use New-Timespan to calculate the time difference between Get-Date (now) and Boottime.
0
 
LVL 71

Expert Comment

by:Chris Dent
ID: 34497724
This question has been classified as abandoned and is being closed as part of the Cleanup Program.  See my comment at the end of the question for more details.
0

Featured Post

Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A project that enables an administrator to perform actions within a user session context not just at the time of login but any time later on day(s) or week(s) later.
My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
Teach the user how to use create log bundles for vCenter Server or ESXi hosts Open vSphere Web Client: Generate vCenter Server and ESXi host log bundle:  Open vCenter Server Appliance Web Management interface and generate log bundle: Open vCenter Se…
Teach the user how to use vSphere Update Manager to update the VMware Tools and virtual machine hardware version Open vSphere Client: Review manual processes for updating VMware Tools and virtual hardware versions: Create a new baseline group in vSp…

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question