Automation

 View Only
  • 1.  How can I get more than 1000 results from TaskManager Collector?

    Posted May 19, 2019 02:47 PM

    $DateStart = (Get-Date).AddDays(-1)

    $TaskNumber = 1000   #1000 max how to fix this?

    $TaskMgr = Get-view TaskManager

    $tFilter = New-Object VMware.Vim.TaskFilterSpec

    $tFilter.Time = New-Object VMware.Vim.TaskFilterSpecByTime

    $tFilter.Time.beginTime = $DateStart

    $tFilter.Time.timeType = "startedTime"

    $tCollector = Get-View ($taskMgr.CreateCollectorForTasks($tFilter))

    $dummy = $tCollector.RewindCollector

    $Tasks = $tCollector.ReadNextTasks($TaskNumber)

      foreach ($Task in $Tasks)

      {

        $TaskName = $Task.Name

        $TaskName

      }

    If I make $TaskNumber =1001 or greater, I get the following error

    Exception calling "ReadNextTasks" with "1" argument(s): "A specified parameter was not correct: maxCount"

    At C:\scripts\Powershell\VMware\vCenter\GetSnapshotTasks.ps1:120 char:1

    + $Tasks = $tCollector.ReadNextTasks($TaskNumber)



  • 2.  RE: How can I get more than 1000 results from TaskManager Collector?
    Best Answer

    Posted May 19, 2019 03:47 PM

    You can't increase the windowsize, that is indeed maxmum 1000 entries.

    But you have a small error in the RewindCollector call (you forgot the parenthesis) which made it be possitioned on the last 'page'.
    Try like this

    $DateStart = (Get-Date).AddDays(-300)

    $TaskNumber = 1000


    $TaskMgr = Get-view TaskManager

    $tFilter = New-Object VMware.Vim.TaskFilterSpec

    $tFilter.Time = New-Object VMware.Vim.TaskFilterSpecByTime

    $tFilter.Time.beginTime = $DateStart

    $tFilter.Time.timeType = "startedTime"


    $tCollector = Get-View ($taskMgr.CreateCollectorForTasks($tFilter))

    $tCollector.RewindCollector()

    do

    {

       $Tasks = $tCollector.ReadNextTasks($TaskNumber)

       $Tasks.Count

    }until($Tasks.Count -eq 0)

    $tCollector.DestroyCollector()



  • 3.  RE: How can I get more than 1000 results from TaskManager Collector?

    Posted May 19, 2019 05:19 PM

    Ah, many thanks!

    So you have to run the ReadNextTasks($TaskNumber) method against the Collector over and over, reading 1000 (or whatever number you specify) at a time.

    I put it in my script.  Working great now.



  • 4.  RE: How can I get more than 1000 results from TaskManager Collector?

    Posted May 19, 2019 06:01 PM

    Indeed, the window slides over the tasks by each call to ReadNextTasks.
    The size of the window is max 1000 entries.