Use the Get-VIEvent cmdlet and filter on TaskEvent, then do a Select-Object on the returned objects.
For example
$start = (Get-Date).AddDays(-7)
$vm = Get-VM -Name MyVM
Get-VIEvent -Entity $vm -Start $start -MaxSamples ([int]::MaxValue) |
Where {$_ -is [VMware.Vim.TaskEvent]}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi.
I can also advise a good function Get-TaskPlus. Author LucD.
Thanks for the information but still need some more direction.
I've worked with the Get-VIEvents a little before but all that shows is the Creation (or Start) Time of an event. How can I dig around to see where the Execution Time column is getting its data from? Is the object called "Execution Time" or something else?
Also, I saw your Get-TaskPlus script but can't figure out how to get that to work either. 😕
LucD blog has a detailed description and examples.
But you will need to add "Execution time". For example, after the line with "...$object.Add("Task Ended", $_.Complete Time)...".
Example of using function Get-TaskPlus
$vm = Get-vm -name 'Vm_Name'
Get-TaskPlus -Entity $vm -MaxSamples 1500 -Details | Export-Csv -Path 'C:\Vm_Tasks.csv' -NoTypeInformation -UseCulture
Example of a string for "execution time"
if ($Details) { $RunTime = New-TimeSpan -Start $_.StartTime.ToLocalTime() -End $_.CompleteTime.ToLocalTime()
$object.Add("Execution time", $("{0}d {1}h {2}m, {3}s." -f $RunTime.Days, $RunTime.Hours, $RunTime.Minutes, $RunTime.Seconds)) }
Okay, after working with my co-worker, we figured out what I was missing. x_x (I had LucD's Get-TaskPlus script in a file and was trying to call the script/file itself instead of having the work underneath the function/script itself).
I got it to work and appreciate the help! 😄