I need to write some powercli to see if a VM is being snapped, vmotioned or possibly other operation. How can I check if a task is running on the specified VM in vCenter?
I know how to get the running tasks in vCenter:
$task = Get-Task -Status Running |
But how do I determine what the target is of the tasks?
Try something like this
Get-Task | where{$_.ObjectId -match '^VirtualMachine'} |
Select StartTime,State,@{N='VM';E={Get-View -Id $_.ObjectId -Property Name | select -ExpandProperty Name}},Description
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Try something like this
Get-Task | where{$_.ObjectId -match '^VirtualMachine'} |
Select StartTime,State,@{N='VM';E={Get-View -Id $_.ObjectId -Property Name | select -ExpandProperty Name}},Description
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
This is the best. Was scrounging the internet just for this answer as I'd struck the same question a few days ago and lo and behold -- found it! Spent several hours trying to do exactly what was provided in this thread and absolutely need to practice/learn so much more.
Thank you again!!
can we filter out only running task and select one VM only
Yes, with a Where-clause
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference