VMware Cloud Community
zhornsby
Enthusiast
Enthusiast

Stop Task via powercli

i have a task that is hung in vcenter 6.5 and i cannot cancel it via the web.

powercli Get-Task state is "running" at 0% for the last hour. do i need to retrieve the task id in order to run a "stop-task"?

the task is "cancel remediating entity"

Tags (1)
Reply
0 Kudos
5 Replies
LucD
Leadership
Leadership

Do you see the Task listed when you do

$taskMgr = Get-View TaskManager

if($taskMgr.RecentTask){

    Get-View -Id $taskMgr.RecentTask

}


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

Reply
0 Kudos
zhornsby
Enthusiast
Enthusiast

unfortunately the task error'ed right as i was reading your comment. regardless, i need to know how to do this for the future. lets pretend the task does show up.

Reply
0 Kudos
LucD
Leadership
Leadership

You could try something like this.

But note that not all tasks are cancelable.

$taskName = '<task-name>'

$taskMgr = Get-View TaskManager

if($taskMgr.RecentTask){

    $task = Get-View -Id $taskMgr.RecentTask | where {$_.Info.Name -eq $taskName}

    if('queued','running' -contains $task.Info.State -and $task.Info.Cancelable){

        $task.CancelTask()

    }

    else{

        if(-not $task.Info.Cancelable){

            Write-Host "Task not cancelable"

        }

        if('queued','running' -notcontains $task.Info.State){

            Write-Host "Task not canceled due to state $($task.Info.State)"

        }

    }

}


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

Reply
0 Kudos
zhornsby
Enthusiast
Enthusiast

was able to re-create the issue. doesnt appear to cancel the task. could it be that this task cant be canceled?

Capture.PNG

Reply
0 Kudos
LucD
Leadership
Leadership

You can check with $task.Info.Cancelable.

I added that condition in the script above.


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

Reply
0 Kudos