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