I'm leaning on StartedTime right now, but need your input.
Submitted reply too soon. I added a check to look for snapshot object id match. So now even if I get multiple tasks that match within a 60 second window, I look @ the task's result to match against the snapshot I'm looking for. Like so:
$Task = Get-VITasksFaster -Entity $VM -Start $Snapshot.created.addseconds(-60) -TimeType "StartedTime" -Finish $Snapshot.created.AddSeconds(1) -Server $VIServer
$Task = $Task | where {$_.result -eq $Snapshot.Id}
What's your question? Queued time would most likely be when the command was actually sent. Started time would be when the Snapshot first kicks off, completed time is when the snapshot completes.
Afaik the CompletedTime is most of the time not correct.
Have a look at the remark at the beginning of the TaskEvent object.
You would have to follow the eventChainId to get at the actual CompletedTime
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
So here is what I'm trying to do for clarification:
I had originally assumed task completedtime would match up to the snapshot created datetime, but that seems to be way off.
Here is the snippet I have for my snapshot management script. I'm extrapolating an e-mail address from the matching AD account to annoy them.
$Task = Get-VITasksFaster -Entity $VM -Start $Snapshot.created.addseconds(-1) -TimeType "StartedTime" -Finish $Snapshot.created.AddSeconds(1) -Server $VIServer
$Events = Get-VIEventsFaster -EventChainID $Task.EventChainID -Server $VIServer # This is really redundant, not needed, just here because I'm too lazy to change the rest of the script.
If ($Events -ne $null){$Username = Get-QADUser $Events.username}
That was my original assumption as well. StartedTime seems to more closely match the Snapshot object's 'created' time.
If you look at Alan's Snapshot Reminder, for which I wrote the Get-SnapshotExtra function, you'll notice I did something similar.
I take the snapshot creation date minus 5 seconds, and then look in the events for a corresponding CreateSnapshot event.
The function does a number of tests to determine the correct event, but it is not fool-proof.
If 2 or more snapshots of the same VM are created in a matter of seconds, the function might not find the correct user.
Also note that this event has the correct State (Success) and the correct user who initiated the snapshot.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Ok, that is actually helpful. I'm taking it one step further and adding an 'entity' object in the taskfilterspec which should reduce the possible return of multiple matching tasks within a 2 second window. After playing w/ my function/script, 'startedtime' seems to match most consistently and I can stay within a two second window. Thanks LucD and vExpert: Brian Graf for your input.
Submitted reply too soon. I added a check to look for snapshot object id match. So now even if I get multiple tasks that match within a 60 second window, I look @ the task's result to match against the snapshot I'm looking for. Like so:
$Task = Get-VITasksFaster -Entity $VM -Start $Snapshot.created.addseconds(-60) -TimeType "StartedTime" -Finish $Snapshot.created.AddSeconds(1) -Server $VIServer
$Task = $Task | where {$_.result -eq $Snapshot.Id}