VMware Cloud Community
admin
Immortal
Immortal

Get-Task does not show any tasks

Does anyone know why I cannot seem to retrieve tasks from my vCenter using the Get-Task commandlet? I'm trying to retrieve vmotion migration tasks but I am unable to retrieve any tasks from all 6 of my vCenters.

I have plenty of tasks when I look at the Tasks & Events tab through the vSphere Client and can see the tasks in the database by running select queries, but I am unable to retrieve them through PowerCLI.

Any ideas?

P.S. I'm running vCenter 4.1.0 build 345043 and PowerCLI 4.1 U1 build 332441.

Many thanks

Theo

Tags (2)
0 Kudos
4 Replies
mattboren
Expert
Expert

Hello, theocrithary1-

Welcome to the forums.  As for Get-Task -- as the help notes, it "retrieves information about the current or recent tasks".  Current or recent -- not any/all tasks that have occurred.  So, once the tasks are no longer "recent" (once they roll off of the "Recent Tasks" pane in the vSphere client), Get-Task no longer retrieves them.

Depending on the level of activity in your vCenters, it could be that there were no recent tasks when you were issuing that command.  Can you verify?

0 Kudos
admin
Immortal
Immortal

Thanks for responding Matt, you are right that it only shows current tasks that display in the recent tasks window.

I was able to validate it by performing an action then running the get-task again to retrieve it.

I think you know what my next question is then Smiley Happy

How do I access the tasks that have rolled off the recent tasks pane but still exist in the tasks & events tab?

get-vievent shows the events, but I don't believe there is a get-vitask or equivalent.

Any suggestions?

Thanks again

Theo

0 Kudos
mattboren
Expert
Expert

Hello-

You are welcome.

Yes, that is a logical next question.  There are some other posts in the communities that address how to get tasks beyond the "recent" ones.  A fine example (by LucD the Master), is at http://communities.vmware.com/message/1491004#1491004.

Give that a read -- it uses the TaskManager managed object (v4.1 API reference at http://www.vmware.com/support/developer/vc-sdk/visdk41pubs/ApiReference/vim.TaskManager.html), creates a collector for TaskInfo objects, and writes some output for tasks with a certain state.  That should get you going on using the TaskManager object to get all the tasks that you want...

0 Kudos
LucD
Leadership
Leadership

I don't think you mentioned why you need access to the Tasks.

If it is only for reporting purposes (and not for managing running tasks), you can still use the Get-VIEvent cmdlet.

In the returned events there is one that has the type TaskEvent.

This type of event contains information about the task under the Info property, but also on which entity the task ran, by who is was started...

A sample TaskEvent script

Get-VIEvent -Start (Get-Date).AddDays(-1) -MaxSamples 1000 | 
where {$_.GetType().Name -eq "TaskEvent"} |
Select CreatedTime,UserName,FullFormattedMessage,@{N="Entity";E={$_.Info.EntityName}},@{N="Task State";E={$_.Info.State}}


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

0 Kudos