Hello,
I'm currently working on a script that I found somewhere. The report should generate a list of VMs that were created 3 months ago but it seems that it only shows the one created this November. Can anyone help me or point me in the right direction?
Process
{
$EventFilterSpecByTime = New-Object VMware.Vim.EventFilterSpecByTime
If ($LastDays)
{
$EventFilterSpecByTime.BeginTime = (get-date).AddDays(-90)
}
$EventFilterSpec = New-Object VMware.Vim.EventFilterSpec
$EventFilterSpec.Time = $EventFilterSpecByTime
$EventFilterSpec.DisableFullMessage = $False
$EventFilterSpec.Type = "VmCreatedEvent","VmDeployedEvent","VmClonedEvent","VmDiscoveredEvent","VmRegisteredEvent"
$EventManager = Get-View EventManager
$NewVmTasks = $EventManager.QueryEvents($EventFilterSpec)
Foreach ($Task in $NewVmTasks)
{
# If VM was deployed from a template then record which template.
If ($Task.Template -and ($Task.SrcTemplate.Vm))
{
$srcTemplate = (Get-View $Task.SrcTemplate.Vm -Property name).Name
}
Else
{
$srcTemplate = $null
}
write-output ""|Select-Object @{
Name="Name"
Expression={$Task.Vm.name}
}, @{
Name="Created"
Expression={$Task.CreatedTime}
}, @{
Name="UserName"
Expression={$Task.UserName}
}, @{
Name="Type"
Expression={$Task.gettype().name}
}, @{
Name="Template"
Expression={$srcTemplate}
}
}
}
Are you sure your VCSA keeps events for at least 3 months?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Good catch LucD! The task and event retention days were set only to 21 days. Are there any other options?
I'm afraid not.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference