PowerCLI

 View Only
  • 1.  How to get tasks within a specific time interval?

    Posted Jul 19, 2022 01:35 PM

    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.



  • 2.  RE: How to get tasks within a specific time interval?

    Posted Jul 19, 2022 02:20 PM

    One aspect that might explain the differences is the TimeType property in the filter.
    If your Get-TaskPlus is referring to my Get-TaskPlus function then in there I used the [vmware.vim.taskfilterspectimeoption]::startedTime
    The other options are queued and completed.
    It is possible that the Web CLient uses another type then startedTime.

    Do all the StartTime values in the returned Tasks fall within the specified interval?



  • 3.  RE: How to get tasks within a specific time interval?

    Posted Jul 19, 2022 04:40 PM

    Yes, I am using your Get-TaskPlus function and all the StartTime values in the returned Tasks also fall within the specified interval, but some of the tasks are missing which also fall within the specified time interval.



  • 4.  RE: How to get tasks within a specific time interval?

    Posted Jul 19, 2022 04:43 PM

    Are you sure that the missing tasks actually started in that interval?
    I just checked in my lab, and for me, it seems to be working ok.



  • 5.  RE: How to get tasks within a specific time interval?

    Posted Jul 20, 2022 06:02 AM

    Yes I am sure that missing tasks also started in the same interval.

    Even if I am running this command: $tasks = Get-TaskPlus -Entity $TemplateName -Start "2022-07-19 05:34:16 AM" -Finish "2022-07-19 05:37:16 AM", the function is not returning even a single task and there are around 100 tasks between this interval [2022-07-19 05:34:16 AM -- 2022-07-19 05:37:16 AM].



  • 6.  RE: How to get tasks within a specific time interval?

    Posted Jul 21, 2022 07:14 AM

    Sorry, I can't reproduce what you are seeing.

    Perhaps some more concrete info like a screenshot of the tasks in the Web client and a run of your code would help.