Skip navigation
VMware

This Question is Answered (go to answer)

1 "helpful" answer available (6 pts)
1,141 Views 11 Replies Last post: Feb 17, 2010 6:41 AM by Salalon RSS
jrhodes Novice 15 posts since
Mar 23, 2005
Currently Being Moderated

Feb 1, 2009 5:58 PM

Last VM powerOn

 

I am trying to pull together a script that will list all my powerd off VMs and then list its last PowerOn.

 

 

Anyone have any ideas?

 

 

Jim

 

 

Niket Hot Shot VMware Employees 91 posts since
Jan 10, 2008
Currently Being Moderated
1. Feb 1, 2009 8:37 PM in response to: jrhodes
Re: Last VM powerOn

Hi,

 

Connect-VIServer -Server

Get-VM | Where {$_.PowerState -eq 'poweredOff' } |  % {$_ | Get-View; Write-Host $_.Name ; Write-Host $_.Runtime.BootTime }

I hope it helps you.

 

Thanks

Niket

LucD Guru User Moderators vExpert 8,981 posts since
Oct 31, 2005
Currently Being Moderated
3. Feb 2, 2009 5:02 AM in response to: jrhodes
Re: Last VM powerOn

Can you try this:

Get-VM | where {$_.PowerState -eq 'poweredOff' } | %{
  $vm = $_ | get-view
  Write-Host $vm.Name $vm.runtime.boottime
}

 

Blog: http://lucd.info | Twitter: @LucD22 | Book co-author: http://powerclibook.com
LucD Guru User Moderators vExpert 8,981 posts since
Oct 31, 2005
Currently Being Moderated
5. Feb 2, 2009 6:10 AM in response to: jrhodes
Re: Last VM powerOn

That is indeed the problem with the bootTime property in the VirtualMachineRuntimeInfo object.

 

A better approach would be to use the power on event.

Something like this

Get-VM <VM-name> | Get-VIEvent -Types Info -MaxSamples 1000 | `
  Where-Object {$_.fullFormattedMessage -match "Power On"} | `
  Sort-Object -property createdTime |  select -last 1 | %{
    Write-Host $_.vm.name $_.createdTime | Out-Default
  }

The problem with this method is that is currently a known issue with the Get-VIEvent cmdlet.

The cmdlet returns only 1000 events independent of what you specify in the -maxSmaples parameter.

If the power on is some time ao it could be that it doesn't fall in the last 1000 events.

 

There is a method to bypass this issue by using the SDK methods.

See  Get-VIEvent maxsamples size

Blog: http://lucd.info | Twitter: @LucD22 | Book co-author: http://powerclibook.com
Salalon Enthusiast 17 posts since
Dec 3, 2009
Currently Being Moderated
7. Feb 17, 2010 2:03 AM in response to: jrhodes
Re: Last VM powerOn

hi all,

 

i need this same report but i have a infraestrture vcenter 2.5 not Sphere, is possible ? how ?

 

Thx.

Regards,

LucD Guru User Moderators vExpert 8,981 posts since
Oct 31, 2005
Currently Being Moderated
8. Feb 17, 2010 4:09 AM in response to: Salalon
Re: Last VM powerOn

You should be able to use the same script with VC 2.5.

 

 

 

 

____________

Blog: LucD notes

Twitter: lucd22

Blog: http://lucd.info | Twitter: @LucD22 | Book co-author: http://powerclibook.com
Salalon Enthusiast 17 posts since
Dec 3, 2009
Currently Being Moderated
9. Feb 17, 2010 5:05 AM in response to: LucD
Re: Last VM powerOn

 

i can´t to execute this script, i have one error:

 

 

 

 

 

Re: Last VM powerOn C:\&gt; & '.\VM Last Poweron Time.ps1'

File C:\VM Last Poweron Time.ps1 cannot be loaded. The file C:\VM Last Poweron

Time.ps1 is not digitally signed. The script will not execute on the system. Pl

ease see "get-help about_signing" for more details..

At line:1 char:2

+ &  &lt;&lt;&lt;&lt; '.\VM Last Poweron Time.ps1'

 

 

 

 

 

Regards,

 

 

LucD Guru User Moderators vExpert 8,981 posts since
Oct 31, 2005
Currently Being Moderated
10. Feb 17, 2010 5:16 AM in response to: Salalon
Re: Last VM powerOn

I suspect you haven't set the execution policy for PowerShell scripts yet.

Do


Set-ExecutionPolicy -ExecutionPolicy RemoteSigned

from the prompt before you start the script.

 

 

 

 

____________

Blog: LucD notes

Twitter: lucd22

Blog: http://lucd.info | Twitter: @LucD22 | Book co-author: http://powerclibook.com
Salalon Enthusiast 17 posts since
Dec 3, 2009
Currently Being Moderated
11. Feb 17, 2010 6:41 AM in response to: LucD
Re: Last VM powerOn

 

hi,

 

 

thx, but now i have a diferent error:

 

 

Re: Last VM powerOn C:\&gt;  get-vm | ./'VM Last Poweron Time.ps1'

Parameter declarations are a comma-separated list of variable names with option

al initializer expressions.

At C:\VM Last Poweron Time.ps1:9 char:11

+         )] &lt;&lt;&lt;&lt;

 

 

Regards,

 

 

Bookmarked By (0)

Share This Page

Communities