VMware Cloud Community
shaka
Enthusiast
Enthusiast
Jump to solution

Check if any tasks are running against a VM in vCenter?

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?

1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

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

View solution in original post

Reply
0 Kudos
4 Replies
LucD
Leadership
Leadership
Jump to solution

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

Reply
0 Kudos
Castrom
Contributor
Contributor
Jump to solution

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!!

Reply
0 Kudos
JitendraOjha1
Contributor
Contributor
Jump to solution

can we filter out only running task and select one VM only 

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Yes, with a Where-clause


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

Reply
0 Kudos