Powershell process not cancelled when job is canceled

book

Article ID: 211625

calendar_today

Updated On:

Products

CA Automic One Automation

Issue/Introduction

When running a Windows job that runs a powershell - .ps1 - script like the following:

call C:\Windows\SysWOW64\WindowsPowerShell\v1.0\Powershell.exe -executionpolicy remotesigned -File C:\scripts\sleep30.ps1

and cancelling before the script is finished, either using MRT or by manually cancelling the object, the powershell process does not end

Cause

This is caused because by default sub processes of a job object are not "bundled" with the job object.

Environment

Release : 12.3

Component :

Resolution

The powershell process cancelling as well can be accomplished by setting the "Use Windows OS Job Object" on the Windows tab of the job to "Yes".  This will group together all child processes for the job (in this case including the .ps1) and when the cancel goes through due to MRT or manual cancellation of the job, it will cancel all sub-processes.  

Additional Information

Please see the "Use Windows OS Job Object" section of the following documentation: https://docs.automic.com/documentation/webhelp/english/AA/12.3/DOCU/12.3/Automic%20Automation%20Guides/help.htm#AWA/Objects/obj_jobs_WIN.htm for more information.

Attachments