Identify Virtual Machine creation and power off date in vCenter Server using vSphere API or PowerCLI
search cancel

Identify Virtual Machine creation and power off date in vCenter Server using vSphere API or PowerCLI

book

Article ID: 375957

calendar_today

Updated On:

Products

VMware vCenter Server

Issue/Introduction

If the virtual machine (VM) creation date or power off date is not currently visible in the vSphere Client, it can be retrieved using the vSphere API.

    • The power-off date and time rely on historical data stored in the vCenter database. 
    • The "createDate" and  "poweredOffTime"  property  is located under VCDB. Information can be accessed via supported vSphere API, such as PowerCLI.

Note :- VM power-off/creation dates might be sometimes unavailable prior to a recent vCenter reboot.

Environment

VMware vCenter Server

Cause

  • vCenter's default retention policy for task and event data is 30 days
  • Identifying a Virtual Machine's creation or power-off date requires querying the vSphere API or PowerCLI if the timeframe is more than 30 days.

Reference Doc: Retention of Events in the vCenter Server Database.

Resolution

Refer the following steps to identify the creation date of Virtual Machines from the vCenter server.

  1. Connect to the vCenter server using PowerCLI.
Connect-VIServer -Server "FQDN_of_vCenterServer"

     2. Get all VMs and their creation dates using the following command.

$vms = Get-VM | Select-Object Name, @{Name="CreationDate";Expression={$_.ExtensionData.Config.CreateDate}}

Refer the following steps to identify the power off date of Virtual Machines from the vCenter server.

The power-off date and time rely on historical data stored in the database. 

  1. Connect to the vCenter server using PowerCLI.
Connect-VIServer -Server "FQDN_of_vCenterServer"

     2. Get all VMs and their power off dates using the following command.

$vms = Get-VM | Where-Object -Property PowerState -eq 'PoweredOff' | Select-Object -Property Name, @{Label='poweredOffTime'; Expression={ $_ | Get-VIEvent -Types Info | Where-Object -Property fullformattedmessage -Match 'shutdown|powered off' | Sort-Object -Property CreatedTime | Select-Object -Last 1 -ExpandProperty CreatedTime }}

Additional Information

  • To download VMware Power_CLI, refer to this link Download URL for VMware Power CLI
  • Only new VMs that were created after upgrading to 6.7 will include this property(createDate) with the creation date
  • VMs that were created prior to version 6.7 will not have the original creation date, but rather a default value of 1970-01-01T00:00:00Z.