Task Data Mining – An improved Get-Task

Quite frequently there are questions in the VMTN PowerCLI Community for scripts that report on the tasks that ran in a vSphere environment.

The PowerCLI pssnapin provides a Get-Task cmdlet, but that only provides information about the recent tasks. An alternative is to use the Get-VIEvent cmdlet and extract all the TaskEvent entries.

But why not use the TaskHistoryCollector and it’s methods ? It provides many filtering options, and since this filtering is done in vSphere itself, this way of working is inherently much faster than using a filter in your script.

In analogy with the Get-VIEventPlus function, I published in my Get the vMotion/svMotion history post, here is the Get-TaskPlus function !

Update February 13th 2020

  • Added logic to break out of do-while loop and destroy the TaskCollector to avoid issues with max 32 collectors

Continue reading Task Data Mining – An improved Get-Task

About Async tasks, the Get-Task cmdlet and a hash table

There was an interesting question in the PowerCLI Community on how to use the -RunAsync parameter. The user wanted to create a number of new guests and start each guest once the creation was complete. This can be done rather easily by using a New-VM cmdlet and piping the result to the Start-VM cmdlet.

Only problem was, the creation of the new guests was done in Async mode.

That’s where the Get-Task cmdlet and the use of a hash table come in handy.

Continue reading About Async tasks, the Get-Task cmdlet and a hash table