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)}}
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
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
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.
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
RVTools will also give you this info and you can extract to csv or excel.
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)}}
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
That worked 🙂 Thank you very much