I have a script which uses Get-TaskPlus script to fetch tasks from vCenter within a specific time interval but it seems that the results are not accurate.
param(
[datetime]$start,
[datetime]$finish,
[Int32]$MaxSamples=250
)
. ".\Get-TaskPlus.ps1"
$Template = "WebTinyCentOS65x86"
$TaskName = "CloneVM_Task"
$TemplateName = Get-Template $Template
$tasks = Get-TaskPlus -Entity $TemplateName -MaxSamples $MaxSamples -Start (Get-Date -Day $start.Day -Month $start.Month -Year $start.Year -Hour $start.Hour -Minute $start.Minute -Second $start.Second) -Finish (Get-Date -Day $finish.Day -Month $finish.Month -Year $finish.Year -Hour $finish.Hour -Minute $finish.Minute -Second $finish.Second) | where name -eq $TaskName
$TimeList = @()
$Time = $tasks.TimeDifference
$TimeList = $TimeList + $Time
$TotalTime = [System.TimeSpan]::new( 0 )
$TimeList | ForEach-Object{ $TotalTime += $_ }
$tasks | Select Name, TaskCreated, TaskStarted, TaskEnded, Entity, VIServer, TimeDifference | ConvertTo-Json
Write-Output "Total Time: $($TotalTime)"
Write-Output "Tasks Count: $($tasks.Count)"
I use this command to run my script: ./getTasks.ps1 -Start "2022-07-19 05:30:22 AM" -Finish "2022-07-19 05:37:22 AM"
This script works fine but somehow picks first task from 2022-07-19 05:30:22 AM and last task from 2022-07-19 05:36:39 AM. When I check the tasks in vCenter, I see that some tasks are not there in the result which occurred between [2022-07-19 05:30:22 AM -- 2022-07-19 05:30:22 AM] and between [2022-07-19 05:36:39 AM -- 2022-07-19 05:37:22 AM].
And also the number of tasks should be 105 but my script shows 220 tasks between this interval.