So I am just having an issue finding where the previous tasks are stored
Get-task only does tasks in the recent pane, and get-vievent only seems to cover the Events portion of the Tasks/Events tab in vCenter.
I just can't find where that big list of Past tasks is located...
Any help would be aprpeciated...
Thanks!
They are in the events, and they are of type TaskEvent.
You can extract them as follows
Get-VIEvent -Start (Get-Date).AddDays(-7) -MaxSamples ([int]::MaxValue) | where {$_.GetType().Name -eq "TaskEvent"}
Anything particular you were looking for ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
They are in the events, and they are of type TaskEvent.
You can extract them as follows
Get-VIEvent -Start (Get-Date).AddDays(-7) -MaxSamples ([int]::MaxValue) | where {$_.GetType().Name -eq "TaskEvent"}
Anything particular you were looking for ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Nope that is perfect, I am working on a script and for part of it I wanted to be able to find specific tasks from the recent tasks pane later on in the big Tasks list...
It looks like the matching value is the get-task property id and the get-vievent property info.task
Thanks LucD! I also think its awesome that in your helpful posts you always link to the SDK . Great Stuff as Always
Most Excellent! I was just thinking about this the other day! Thanks guys!
Ok, one more quick question.
Get-VIEvent |?{($_.gettype().name -eq "taskevent")}
I am trying to find where in that object it actually states whether the task errored or completed.
I know I can filter with get-vievent -type, however I don't know its status and I want the get-vievent object to tell me....I see the Error, Result, Progress properties under Info, but I am looking at an event that did fail and all of those properties are empty. So I am not sure how to script a return of the tasks result.
I know I can get the Result and Error from a get-task, but I am trying to get it from get-vievent...
Any other assistance would be much appreciated!!!
To get the actual completion status of the tasks we will need to use the TaskHistoryCollector.
Something like this
$hours = 24 # Number of hours back
$start = (Get-Date).AddHours(-$hours) $tasknumber = 999 # Windowsize for task collector
$taskMgr = Get-View TaskManager $tFilter = New-Object VMware.Vim.TaskFilterSpec $tFilter.Time = New-Object VMware.Vim.TaskFilterSpecByTime $tFilter.Time.beginTime = $start
$tFilter.Time.timeType = "startedTime"
$tCollector = Get-View ($taskMgr.CreateCollectorForTasks($tFilter)) $dummy = $tCollector.RewindCollector $tasks = $tCollector.ReadNextTasks($tasknumber) while($tasks){ foreach($task in $tasks){ New-Object PSObject -Property @{ Name = $task.EntityName Task = $task.DescriptionId Start = $task.StartTime Finish = $task.CompleteTime Result = $task.State User = $task.Reason.UserName } } } $tasks = $tCollector.ReadNextTasks($tasknumber) # By default 32 task collectors are allowed. Destroy this task collector.
$tCollector.DestroyCollector()
You can find another example, that also looks at the associated event chain, in my Events – Part 8 – vMotion history post.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hello everybody,
how to query for past task from Id?
Assuming you have the Task object in variable $task, you could do
Get-VIEvent -MaxSamples ([int]::MaxValue) |
where {$_ -is [VMware.Vim.TaskEvent] -and $task.Id.Replace('Task-','') -eq $_.Info.Key}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks LucD for your reply.
I noticed that $tasknumber could not be grater than 1000, isn't it?
Which property are you referring to in $tasknumber ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
$tasknumber = 999 # Windowsize for task collector
I think it's a simple variable
That is the windowsize for the TaskHistoryCollector used in the other script.
Each time you do a ReadNextTasks, you get that many, or less, task objects returned.
It is not related to the Task itself.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Is there a way to get all tasks from a past point in time?
windowsize variable limits this behaviour...
Hi Lucd,
Is any parameter is there to get the previous vCenter tasks on hourly basis I mean suppose I want to see the taks for last 2 -3 hours how can I do that.
You will have to use the Start and Finish parameters on the Get-VIEvent cmdlet.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi,
with Get-Task I am getting the details of currently queued/running etc. However in vSphere client under Recent Tasks, I am noticing some tasks which are 15 days and older. is there a cmdlet I can use to get the older tasks also in Recent Tasks tab.
No, not in the Web Client (if that is what you mean).
Use the Get-VIEvent cmdlet and filter on TaskEven objects.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference