VMware Cloud Community
LeaV97
Enthusiast
Enthusiast
Jump to solution

VMs powered off for more than 14 days

So I need report of all VMs powered off more than 14 days and who powered off the VM.  I can get the powered off VMs.  I can get who powered them off.  But when I get the list of powered of VMs and who powered them off, I'm missing the name of the VM.  I'm guessing I'm missing something simple

get-vm | where {$_.powerstate -eq "PoweredOff"} |Get-VIEvent | where { $_.fullFormatted Message -like "Task: Power off*" } | select createdTime, userName, fullFotmattedMessage | where {$_.createdtime -lt (get-date).adddays(-14)}

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Try like this

get-vm | where {$_.powerstate -eq "PoweredOff"} |

Get-VIEvent | where {  $_.fullFormatted Message -like "Task: Power off*" } |

select  createdTime, userName, fullFotmattedMessage,@{N="VM";E={$_.Vm.Name}} |

where {$_.createdtime -lt  (get-date).adddays(-14)}


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

View solution in original post

Reply
0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

Try like this

get-vm | where {$_.powerstate -eq "PoweredOff"} |

Get-VIEvent | where {  $_.fullFormatted Message -like "Task: Power off*" } |

select  createdTime, userName, fullFotmattedMessage,@{N="VM";E={$_.Vm.Name}} |

where {$_.createdtime -lt  (get-date).adddays(-14)}


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

Reply
0 Kudos
LeaV97
Enthusiast
Enthusiast
Jump to solution

Thanks LucD,

That works and now that I know how I've used it in 2 other scripts.

Reply
0 Kudos