search cancel

No output from SD Procedure executing a Powershell script

book

Article ID: 255719

calendar_today

Updated On:

Products

CA Client Automation - IT Client Manager CA Client Automation CA Client Automation - Software Delivery

Issue/Introduction

In a SD Package a procedure executing a powershell script does not redirect the output to Job output file.

>$rf parameter does not work.

Example :

Environment

CA Client Automation - All Version.

Cause

Following command line is executed for a powershell script by SD Agent
 
powershell.exe -File  test.ps1 2>&1 >C:\PROGRA~2\CA\DSM\Agent\units\00000001\usd\sdjexec\D7910711-BE01-48DE-9887-4B1FECECABAA.res
 
sdjesdprocedureexecu|000533|NOTIFY | SDJESDProcedureExecutorIf::Execute executing powershell.exe -File  test.ps1 2>&1 >C:\PROGRA~2\CA\DSM\Agent\units\00000001\usd\sdjexec\D7910711-BE01-48DE-9887-4B1FECECABAA.res
 
 
Redirection does not work because these parameters 
2>&1 >C:\PROGRA~2\CA\DSM\Agent\units\00000001\usd\sdjexec\D7910711-BE01-48DE-9887-4B1FECECABAA.res
are seen as parameters for test.ps1 script 
 
In help of powershell.exe we could read this :
-File
    Runs the specified script in the local scope ("dot-sourced"), so that the
    functions and variables that the script creates are available in the
    current session. Enter the script file path and any parameters.
    File must be the last parameter in the command, because all characters
    typed after the File parameter name are interpreted
    as the script file path followed by the script parameters.

Resolution

As solution create a .bat file which executes the powershell.exe script.

Example :

1- Create a file test.bat containing these lines :

@echo off
powershell.exe -ExecutionPolicy ByPass -File test.ps1


2- Create a procedure with test.bat and 2>&1 >$rf in parameters 

Attachments