CA Workload Automation ESP Edition

Expand all | Collapse all

Chain commands in job definition with PowerShell

Jump to Best Answer
  • 1.  Chain commands in job definition with PowerShell

    Posted 03-26-2020 04:24 PM
    I am trying to chain commands in PowerShell as we do with CMD exe. For example, if I want to chain multiple command-line commands together in a wob I use the "&" character. These wob echos to the spool file, retrieves a dir listing for the home dir, changes loc to C temp and get a dir listing for C temp. This works fine.

    NT_JOB TEST01
    AGENT SCWKLDT1
    ENVAR HOME="C:\PROGRAM FILES\WORKLOAD_AUTOMATION"\WORKLOAD_AGENT"
    CMDNAME C:\WINDOWS\SYSTEM32\CMD.EXE
    ARGS /C ECHO "STARTING CHAIN" & DIR & PUSHD C:\TEMP & DIR
    RUN ANY
    ENDJOB

    Trying to do the same thing with PowerShell.
    I can run each cmd individually, but I am not able to chain them together. I have tried, "&", "|", ";" and several other variations found online. Any help chaining PowerShell commands together in an ESP wob would be appreciated.

    Example
    NT_JOB A079011A.TEST01
    AGENT SCWKLDT1
    ENVAR HOME="C:\PROGRAM FILES\WORKLOAD_AUTOMATION"\WORKLOAD_AGENT"
    CMDNAME POWERSHELL.EXE
    ARGS Write-Host "Starting_Chain" ; Get-ChildItem ; push-Location C:\temp ; Get-Child-Item
    RUN ANY
    ENDJOB

    Thank you!

    ------------------------------
    Eric Kammerer
    IT Systems Engineer | Workload Engineering
    Progressive Insurance
    ------------------------------


  • 2.  RE: Chain commands in job definition with PowerShell
    Best Answer

    Posted 03-26-2020 05:15 PM
     In the ARGS statement changed double-quotes to single-quotes the wrapped all the ARGS in double-quotes.

    ARGS /c "Write-Host 'Starting_Chain';Write-Host 'Ending_Chain'"

    Job Output          

    ---------------------------------------

    Output of messages for workload object

    Start date 03/26/2020 17:06:51.635-0400

    ---------------------------------------
    Starting_Chain
    Ending_Chain

                                          







    ------------------------------
    Senior Systems Analyst
    UPS
    ------------------------------



  • 3.  RE: Chain commands in job definition with PowerShell

    Posted 03-27-2020 07:50 AM
    Rick, this worked perfectly. I have been reading over some of your other posts in this community and you are spot on again. Thank you for being so helpful to everyone in the forum.

    ------------------------------
    Eric Kammerer
    IT Systems Engineer | Workload Engineering
    Progressive Insurance
    ------------------------------