Hi,
I'm looking for an exact script to generate CSV file for extracting the date and time of all VMs that has been created since last 2015. Sorry, I'm not familiar on PowerCLI commands.
Thank you in advance.
There is currently no property for a VM that records its creation date (exception the VMs created on VCAWS in vSPhere 6.7).
The only source to find the creation date, is to scan the events on a vCenter.
But since events are only kept for a limited time (up to 1 year), you will not be able to go that far back.
On the available events you could do (mind that this script might take some time to run, depending on the number of events that are kept)
Get-VIEvent -MaxSamples ([int]::MaxValue) |
where{$_ -is [VMware.Vim.VmCreatedEvent] -or $_ -is [VMware.Vim.VmClonedEvent] -or $_ -is [VMware.Vim.VmDeployedEvent] -or $_ -is [VMware.Vim.VmRegisteredEvent]} |
Sort-Object -Property CreatedTime |
Select CreatedTime,UserName,Template,
@{N='VM';E={$_.VM.Name}},
@{N='Datacenter';E={$_.Datacenter.Name}},
@{N='VMHost';E={$_.Host.Name}},
@{N='Cluster';E={$_.ComputeResource.Name}},
@{N='Type';E={$_.GetType().Name}} |
Export-Csv -Path .\report.csv -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
There is currently no property for a VM that records its creation date (exception the VMs created on VCAWS in vSPhere 6.7).
The only source to find the creation date, is to scan the events on a vCenter.
But since events are only kept for a limited time (up to 1 year), you will not be able to go that far back.
On the available events you could do (mind that this script might take some time to run, depending on the number of events that are kept)
Get-VIEvent -MaxSamples ([int]::MaxValue) |
where{$_ -is [VMware.Vim.VmCreatedEvent] -or $_ -is [VMware.Vim.VmClonedEvent] -or $_ -is [VMware.Vim.VmDeployedEvent] -or $_ -is [VMware.Vim.VmRegisteredEvent]} |
Sort-Object -Property CreatedTime |
Select CreatedTime,UserName,Template,
@{N='VM';E={$_.VM.Name}},
@{N='Datacenter';E={$_.Datacenter.Name}},
@{N='VMHost';E={$_.Host.Name}},
@{N='Cluster';E={$_.ComputeResource.Name}},
@{N='Type';E={$_.GetType().Name}} |
Export-Csv -Path .\report.csv -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference