VMware Cloud Community
mdangel1
Enthusiast
Enthusiast
Jump to solution

VM powered on

Hello All,

I need an updated script to show  me how long 1 VM or a group of VMs have been powered on.

Had an outage a few days ago and I need to know which VMs where rebooted.

THANK YOU SO MUCH

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Change the Get-VM at the beginning accordingly


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

View solution in original post

0 Kudos
6 Replies
LucD
Leadership
Leadership
Jump to solution

Did you check the events with Get-VIEvent?


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

0 Kudos
mdangel1
Enthusiast
Enthusiast
Jump to solution

Thank you for you reply, very appreciated!

Can you help me with a full script utilizing Get-VIEvent?  

0 Kudos
LucD
Leadership
Leadership
Jump to solution

You could do something like this, which will list all VMs that were powered on in the last 7 days, and will show the last poweron date.

 

$vms = Get-VM
$start = (Get-Date).AddDays(-7)

Get-VIEvent -Entity $vms -Start $start -MaxSamples ([int]::MaxValue) |
where{$_ -is [VMware.Vim.VmPoweredOnEvent]} |
Group-Object -Property {$_.VM.Name} -PipelineVariable group |
ForEach-Object -Process {
    New-Object -TypeName PSObject -Property @{
        VM =$group.Name
        LastPowerOn = $group.Group | Sort-Object -Property CreatedTime -Descending |
            Select -Last 1 | Select -ExpandProperty CreatedTime
    }
}

 


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

0 Kudos
mdangel1
Enthusiast
Enthusiast
Jump to solution

Thank you so much!! will test as soon as possible

 

0 Kudos
mdangel1
Enthusiast
Enthusiast
Jump to solution

Is there a script to determine 1 or a handful of VMs how long they have been up? 

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Change the Get-VM at the beginning accordingly


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

0 Kudos