Select Page

Get VM’s in vCenter Last Powered Off Date via VMware PowerCLI

Updated 25/04/2017 – Added code snippet.

Please refer to my post on how to connect to vCenter via PowerCLI If you have not completed this before, It can be found here

Connect-VIServer -Server HOSTNAME

Create the following script and call it Get-VMLastPowerOnOffDate.ps1

[et_pb_dmb_code_snippet admin_label=”Code Snippet” style=”default” linenums=”off” usetabwidth=”off” use_border_color=”off” border_color=”#ffffff” border_style=”solid”]ZnVuY3Rpb24gR2V0LVZNTGFzdFBvd2VyZWRPZmZEYXRlIHsKICBwYXJhbShbUGFyYW1ldGVyKE1hbmRhdG9yeT0kdHJ1ZSxWYWx1ZUZyb21QaXBlbGluZT0kdHJ1ZSldCiAgICAgICAgW1ZNd2FyZS5WaW1BdXRvbWF0aW9uLlZpQ29yZS5JbXBsLlYxLkludmVudG9yeS5WaXJ0dWFsTWFjaGluZUltcGxdICR2bSkKICBwcm9jZXNzIHsKICAgICRSZXBvcnQgPSAiIiB8IFNlbGVjdC1PYmplY3QgLVByb3BlcnR5IE5hbWUsTGFzdFBvd2VyZWRPZmZEYXRlLFVzZXJOYW1lCgkkUmVwb3J0Lk5hbWUgPSAkXy5OYW1lCiAgICAkRXZlbnQgPSBHZXQtVklFdmVudCAtRW50aXR5ICR2bSB8IFNvcnQtT2JqZWN0IC1Qcm9wZXJ0eSBDcmVhdGVkVGltZSAtRGVzY2VuZGluZyB8IGAKICAgICAgV2hlcmUtT2JqZWN0IHsgJF8uR2V0dHlwZSgpLk5hbWUgLWVxICJWbVBvd2VyZWRPZmZFdmVudCIgfSB8IGAKCSAgU2VsZWN0LU9iamVjdCAtRmlyc3QgMQoJJFJlcG9ydC5MYXN0UG93ZXJlZE9mZkRhdGUgPSAkRXZlbnQuQ3JlYXRlZFRpbWUKCSRSZXBvcnQuVXNlck5hbWUgPSAkRXZlbnQuVXNlck5hbWUKCSRSZXBvcnQKICB9Cn0KCmZ1bmN0aW9uIEdldC1WTUxhc3RQb3dlcmVkT25EYXRlIHsKICBwYXJhbShb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bWV9Ck5ldy1WSVByb3BlcnR5IC1OYW1lIExhc3RQb3dlcmVkT25EYXRlIC1PYmplY3RUeXBlIFZpcnR1YWxNYWNoaW5lIC1WYWx1ZSB7KEdldC1WTUxhc3RQb3dlcmVkT25EYXRlIC12bSAkQXJnc1swXSkuTGFzdFBvd2VyZWRPbkRhdGV9Ck5ldy1WSVByb3BlcnR5IC1OYW1lIExhc3RQb3dlcmVkT25Vc2VyTmFtZSAtT2JqZWN0VHlwZSBWaXJ0dWFsTWFjaGluZSAtVmFsdWUgeyhHZXQtVk1MYXN0UG93ZXJlZE9uRGF0ZSAtdm0gJEFyZ3NbMF0pLlVzZXJOYW1lfQoKR2V0LVZNIHwgU2VsZWN0LU9iamVjdCAtcHJvcGVydHkgTmFtZSxMYXN0UG93ZXJlZE9uRGF0ZSxMYXN0UG93ZXJlZE9uVXNlck5hbWUsTGFzdFBvd2VyZWRPZmZEYXRlLExhc3RQb3dlcmVkT2ZmVXNlck5hbWU=[/et_pb_dmb_code_snippet]

You will need to run the script by typing the below –

.\Get-VMLastPowerOnOffDate.ps1

Run Get VMLastPowerOnOffDate - Get VM's in vCenter Last Powered Off Date via VMware PowerCLI

Example of the results can be found below –

Get VMLastPowerOnOffDate - Get VM's in vCenter Last Powered Off Date via VMware PowerCLI

Pin It on Pinterest

Share This