VMware Cloud Community
baber
Expert
Expert

How can stop / kill running tasks in vcenter with powercli

I want force stop or kill running tasks in vcenter . 

Now when I am running follow command :

Get-Task -Status "Running"

it shows running tasks 

Name ;                          state                        complete: 

Deploy myvm               running                      0%

Now I don't want to use variable for kill or stop tasks 

I want use stop-task  command with task name . would you please help me about it ?

Please mark helpful or correct if my answer resolved your issue.
0 Kudos
9 Replies
LucD
Leadership
Leadership

You will have to identify the Task you want to kill.
How will you do that? Based on the Task name (like Deploy myvm)?

If yes, you could do

Get-Task -Status 'Running' |
where {$_.Name -eq 'Deploy myvm'} |
Stop-Task -Confirm:$false


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

0 Kudos
baber
Expert
Expert

Thanks . But want to now is there any solution to insert task name manually and run two command 

first command just show current running tasks :

Get-Task -Status 'Running'

now with above command we can find task name then run stop-task command with task name ? such as this 

stop-task -name "deploy testvm"

Please mark helpful or correct if my answer resolved your issue.
0 Kudos
LucD
Leadership
Leadership

The Stop-Task cmdlet only accepts a Task object as parameter, not a name.


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

0 Kudos
baber
Expert
Expert

Sometimes we want kill a task via UI and click on task and cancel it but it usually take a few minutes and sometimes more than minutes it takes to kill can we use that command to kill it force ? Does it kill task immediately ?

Please mark helpful or correct if my answer resolved your issue.
0 Kudos
LucD
Leadership
Leadership

The cmdlet Stop-Task does call the same API that the Web client uses, so it will take just as long.


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

0 Kudos
baber
Expert
Expert

As I find out Is that your means there is not any solution to kill  force a running process  ? Does it take same time such as cancel in the UI ?

Please mark helpful or correct if my answer resolved your issue.
Tags (1)
0 Kudos
LucD
Leadership
Leadership

I have no clue what you mean I'm afraid.


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

0 Kudos
baber
Expert
Expert

I want to know is there any difference if we kill a job in the UI or Kill it by Powercli ?  Because most of the time when we kill a job in the UI it will takes time and cannot kill it immediately Now want to know Will the job kill immediately (force) when we do it by Powercli ?

Please mark helpful or correct if my answer resolved your issue.
0 Kudos
LucD
Leadership
Leadership

As I said earlier, both methods will use the same underlying API.


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

0 Kudos