VMware Cloud Community
ganapa2000
Hot Shot
Hot Shot
Jump to solution

Get VM Creation based on Creation Date

Hi,

How can I get VMs info with based on Creation Date. We need to know, how many VMs are created from last two days. I know, Get-VIEvent gets me the details but our organization has set active event only for 15 days

get-vm | select Name, @{n="createdate"; e={$_.extensiondata.config.createDate -lt  (Get-Date).AddDays(-2)}}

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You will need to add a Where-clause

Get-VM |
Where-Object { $_.extensiondata.config.createDate -ge (Get-Date).AddDays(-7) } |
Select-Object Name, @{n = "createdate"; e = { $_.extensiondata.config.createDate}}


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

View solution in original post

0 Kudos
7 Replies
LucD
Leadership
Leadership
Jump to solution

That property is only available when the VM was created in an environment where the ESXi node and the VCSA are on 6.7 or later.

If events are only kept for 15 days, you should be able to get the VMs created in the last 2 days.


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

0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

Hi LucD,

Yes we have all our ESXi 6.7 or later, sometimes we have a requirement where I might need to extract the VM details from particular date or month which is beyond 15 days, then it would be difficult, hence was going for that approach. 

 

0 Kudos
LucD
Leadership
Leadership
Jump to solution

If that VM was created in a full 6.7 environment, that property should be present


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

0 Kudos
Quickdraw
Enthusiast
Enthusiast
Jump to solution

RVTools will also give you this info and you can extract to csv or excel. 

0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

LucD,

how can I filter based on the createdDate like last 7 days or 45 days from the output I need.

get-vm | select Name, @{n="createdate"; e={$_.extensiondata.config.createDate -lt  (Get-Date).AddDays(-2)}}

0 Kudos
LucD
Leadership
Leadership
Jump to solution

You will need to add a Where-clause

Get-VM |
Where-Object { $_.extensiondata.config.createDate -ge (Get-Date).AddDays(-7) } |
Select-Object Name, @{n = "createdate"; e = { $_.extensiondata.config.createDate}}


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

0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

That worked 🙂  Thank you very much

0 Kudos