Unable to run a job which runs powershell script

Document ID : KB000006049
Last Modified Date : 14/02/2018
Show Technical Document Details
Issue:

When attempting to run a job on Windows agent that executes a PowerShell script, the job goes to RUNNING status and the script is not executed. The job stays in RUNNING status until it is issued a KILLJOB event. 

The job command is specified in the format...

command: c:\test\ps_script.ps1

Environment:
Windows
Cause:

The WA Agent on Windows executes commands through the Windows command-line interpreter (cmd.exe). When executing a PowerShell script from the Windows command-line interpreter, you must run it using the 'powershell -file <script_name>' command. Otherwise, the script is just opened in the default text editor associated with .ps1 files on the Windows machine. This is why the job will stay in the RUNNING status and not actually execute the script. When the job is launched, the script is opened into a text editor in the background on the Windows agent machine and does not actually execute. It also does not exit. 

Resolution:

Modify the job's command attribute so that the script is executed through PowerShell.

For example...

command: powershell -file c\:\test\ps_script.ps1