VMware Cloud Community
CSIEnvironments
Enthusiast
Enthusiast

Get-Task Error

Hi,

I get the following error running get-task. I seems to display the first 3000 odd tasks but then errors:

PS C:\> get-task

jobDelete                      Success           100 11:18:48 AM  11:18:48 AM

jobDisable                     Success           100 11:18:44 AM  11:18:44 AM

jobEnable                      Success           100 11:18:42 AM  11:18:42 AM

jobDisable                     Success           100 11:18:40 AM  11:18:40 AM

commonPurgeDeletedItem         Success           100 11:18:22 AM  11:18:22 AM

vdcDeleteVdc                   Success           100 11:18:22 AM  11:18:22 AM

jobDisable                     Success           100 11:18:17 AM  11:18:17 AM

vdcCreateVdc                   Error             100 11:02:57 AM  11:07:58 AM

jobVcStartConnection           Success           100 10:50:50 AM  10:50:50 AM

rclPrepareHost                 Success           100 10:48:42 AM  10:50:40 AM

jobCrosshostEnable             Success           100 10:50:26 AM  10:50:40 AM

jobInstall                     Success           100 10:48:42 AM  10:50:26 AM

jobVcStartConnection           Success           100 10:50:11 AM  10:50:11 AM

jobVcStartConnection           Success           100 10:50:09 AM  10:50:09 AM

rclPrepareHost                 Error             100 10:46:39 AM  10:48:14 AM

jobInstall                     Error             100 10:46:39 AM  10:48:14 AM

rclPrepareHost                 Error             100 10:44:03 AM  10:45:43 AM

jobInstall                     Error             100 10:44:03 AM  10:45:43 AM

rclPrepareHost                 Success           100 10:41:43 AM  10:43:33 AM

jobCrosshostEnable             Success           100 10:43:17 AM  10:43:33 AM

jobInstall                     Success           100 10:41:43 AM  10:43:17 AM

Get-Task : 5/24/2013 1:54:49 PM    Get-Task        There is an error in XML document (33, 769).

At line:1 char:9

+ get-task <<<<

    + CategoryInfo          : NotSpecified: (:) [Get-Task], VimException

    + FullyQualifiedErrorId : SdkUtil10_ErrorHandledStream_GetWrappedEnumerable,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetTask

Is there anyway to trim the amount of tasks in that list? Either via the database or from the vcloud cell. I've tried using Get-Task | select id -First 100 but it still evaluates all values. I must have a corrupt entry?

Any ideas?

Thanks!

Reply
0 Kudos
6 Replies
LucD
Leadership
Leadership

With the Get-Task cmdlet you can only filter on the Status (Error, Queued, Running, Success, Unknown) or the Task ID.

For more filtering options you will have to use the TaskCollector (see CreateCollectorForTasks).

In the TaskFilterSpec you have more filtering options (entity, task type, timerange, username...).

Let me know if you need a sample ?


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

CSIEnvironments
Enthusiast
Enthusiast

Thanks Luc, I get this error without doing any filtering. Just calling get-task errors after about 40 seconds of running.

Reply
0 Kudos
LucD
Leadership
Leadership

That's probably due to the amount of Tasks it finds.

With the other method I gave above, you can be more selective in which tasks you retrieve.


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

CSIEnvironments
Enthusiast
Enthusiast

Thanks that's a possibility. Would you mind sharing some examples on filtering get-task if you have Smiley Happy Or is it in the PowerCLI reference guide? If so I'll get it from there. Thanks Luc!

Reply
0 Kudos
LucD
Leadership
Leadership

This is a sample script that uses the TaskCollector.

In the script I retrieve the tasks from the last day, but other filtering options are possible.

By what would you like to filter the tasks ?

$Finish = Get-Date
$Start = $Finish.AddDays(-1)

$tskMgr = Get-View TaskManager

$filter = New-Object VMware.Vim.TaskFilterSpec
$filter.Time = New-Object VMware.Vim.TaskFilterSpecByTime
$filter.Time.beginTime = $Start
$filter.Time.endTime = $Finish
$filter.Time.timeType = [vmware.vim.taskfilterspectimeoption]::startedTime

$tCollector = Get-View ($tskMgr.CreateCollectorForTasks($filter))
$tasks = $tCollector.ReadNextTasks(100)
while($tasks){
 
$tasks | Select Name,StartTime,EntityName,@{N="User";E={$_.Reason.UserName}}
 
$tasks = $tCollector.ReadNextTasks(100)
}

$tCollector.DestroyCollector()


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

Reply
0 Kudos
CSIEnvironments
Enthusiast
Enthusiast

I'm trying to make my script wait until it completes the previous task before continuing.

I tried this:

$task = $vdc.ExtensionData.InstantiateVAppTemplate($instParams)

$task.wait()

But then got this error: Method invocation failed because [VMware.VimAutomation.Cloud.Views.VApp] doesn't contain a method named 'wait'.

So I'm trying it this way (not sure if it will produce the same error):

$task = $vdc.ExtensionData.InstantiateVAppTemplate($instParams)

$task = Get-Task | where { $_.id -eq $task }

Wait-Task $task

My current hack method is this. This works but not sure its the most efficient way:

$task = $vdc.ExtensionData.InstantiateVAppTemplate($instParams)

while ($task.tasks) {

write-host "Still adding to Cloud......";

start-sleep 20

$task.UpdateViewData()

}

Reply
0 Kudos