Automation

 View Only
  • 1.  VMs powered off for more than 14 days

    Posted Apr 15, 2013 03:12 PM

    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)}



  • 2.  RE: VMs powered off for more than 14 days
    Best Answer

    Posted Apr 15, 2013 05:37 PM

    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)}



  • 3.  RE: VMs powered off for more than 14 days

    Posted Apr 16, 2013 01:41 PM

    Thanks LucD,

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