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
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
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
Great answer,
where do you get these informations? The Syntax, objects and so on?
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
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