VMware Cloud Community
smerten
Contributor
Contributor
Jump to solution

Find VMs with downtime longer then one week

Hi Community,

I look for a command to find VMs where the downtime ist longer then one week.

I need these Informations to:

Get-VM | Select-Object -Property "Name","Description","NumCPU","MemoryMB"

I hope someone has a answer.

Best wishes

Jörn

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

I think the following script should produce these VM names.

It starts by only taking the currently PoweredOff VMs.

Then it collects all the VMs that were powered off in the last week.

And finally it combines the 2 lists to find those VMs that were powered off longer than a week ago.

Let me know if this works for you.

$vms = (Get-VM | where {$_.PowerState -eq "PoweredOff"}) | %{$_.Name}
$events = Get-VIEvent -Start (Get-Date).AddDays(-7) | where{$_.FullFormattedMessage -like "Task: Power off*"}
$lastweekVM = $events | %{$_.Vm.Name}
$longer1week = $vms | where {!($lastweekVM -contains $_)}
$longer1week

____________

Blog: LucD notes

Twitter: lucd22


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

View solution in original post

Reply
0 Kudos
4 Replies
LucD
Leadership
Leadership
Jump to solution

I think the following script should produce these VM names.

It starts by only taking the currently PoweredOff VMs.

Then it collects all the VMs that were powered off in the last week.

And finally it combines the 2 lists to find those VMs that were powered off longer than a week ago.

Let me know if this works for you.

$vms = (Get-VM | where {$_.PowerState -eq "PoweredOff"}) | %{$_.Name}
$events = Get-VIEvent -Start (Get-Date).AddDays(-7) | where{$_.FullFormattedMessage -like "Task: Power off*"}
$lastweekVM = $events | %{$_.Vm.Name}
$longer1week = $vms | where {!($lastweekVM -contains $_)}
$longer1week

____________

Blog: LucD notes

Twitter: lucd22


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

Reply
0 Kudos
smerten
Contributor
Contributor
Jump to solution

Great answer,

where do you get these informations? The Syntax, objects and so on?

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

The syntax is standard PowerShell. See My PS library for some pointers.

For the events have a look at my Events, Dear Boy, Events – Part 2 post.

And there are some other event-related posts on my blogsite.

____________

Blog: LucD notes

Twitter: lucd22


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

LucD
Leadership
Leadership
Jump to solution

Have a look at Events – Part 5 : Powered of for more than 1 week ?.

The script can be a lot faster with a small change.

____________

Blog: LucD notes

Twitter: lucd22


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