VMware Cloud Community
Sankavaraj
Contributor
Contributor
Jump to solution

Can i get PowerCLI Script for More than 10 Days Power off VM list in the VCenter

Can i get PowerCLI Script for More than 10 Days Power off VM list in the VCenter... pls Assist

1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

If my assumption was correct, try like this

$poweredOff = Get-VIEvent -Start (Get-Date).AddDays(-10) -MaxSamples ([int]::MaxValue) |

    where{$_ -is [VMware.Vim.VmPoweredOffEvent]} | %{$_.Vm.Name}

Get-VM  | where{$_.PowerState -eq 'poweredoff' -and $poweredOff -notcontains $_.Name} | select -ExpandProperty Name


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

View solution in original post

0 Kudos
5 Replies
LucD
Leadership
Leadership
Jump to solution

To make sure I get the question, you want a script that lists the VMs that have been powered off for more than 10 days?


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

0 Kudos
LucD
Leadership
Leadership
Jump to solution

If my assumption was correct, try like this

$poweredOff = Get-VIEvent -Start (Get-Date).AddDays(-10) -MaxSamples ([int]::MaxValue) |

    where{$_ -is [VMware.Vim.VmPoweredOffEvent]} | %{$_.Vm.Name}

Get-VM  | where{$_.PowerState -eq 'poweredoff' -and $poweredOff -notcontains $_.Name} | select -ExpandProperty Name


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

0 Kudos
Sankavaraj
Contributor
Contributor
Jump to solution

You are right lucid ... thanks for your quick response...i will check and update you

0 Kudos
Sankavaraj
Contributor
Contributor
Jump to solution

Thanks Lucd your script work awesome... if possible , can i get VM power off date also.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

That depends a bit on how long you keep the events on the vCenter.

The script could look something like the one in 2. Re: Powered off VM's and how long they have been powered off by.


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