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)}
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
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
Thanks LucD,
That works and now that I know how I've used it in 2 other scripts.