VMware Cloud Community
RonRosenkoetter
Contributor
Contributor
Jump to solution

How can I get more than 1000 results from TaskManager Collector?

$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)

1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

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()


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
3 Replies
LucD
Leadership
Leadership
Jump to solution

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()


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
RonRosenkoetter
Contributor
Contributor
Jump to solution

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.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

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


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos