Contributor
Contributor

Find VMs with downtime longer then one week

Jump to solution

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

0 Kudos
1 Solution

Accepted Solutions
Leadership
Leadership

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

0 Kudos
4 Replies
Leadership
Leadership

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

0 Kudos
Contributor
Contributor

Great answer,

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

0 Kudos
Leadership
Leadership

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

Leadership
Leadership

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