Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  • Find the below examples for download (.json upload)run-powershell-unix.workflow.json
  • In order to directly run PowerShell® script code from a JS7 shell job script the recommended approach is to use a shebang like this:

    Code Block
    languagebash
    titleExample how run PowerShell® script code with a shebang
    linenumberstrue
    #!/usr/bin/env pwsh
     
    Write-Output "Hello"
    Write-Output "world"
  • As a bad alternative the PowerShell® executable can be invoked directly and can be parameterized like this

    Code Block
    languagebash
    titleExample how to run PowerShell® script code from a single line
    linenumberstrue
    pwsh -NoLogo -NonInteractive -Command '& { Echo "Hello"; Echo "World"; }'

    Explanation:

    • Consider the quoting: when using the -Command parameter then the PowerShell® script has to be specified from a string. This includes:
      • quoting the script by single quotes.
      • quoting code inside the script with double quotes or using escape characters for single quotes.
    • Note that each PowerShell® command has to be terminated with a semicolon.

  • An even weirder more weird way of running PowerShell® code from JS7 job scripts includes:

    Code Block
    languagebash
    titleExample how to run PowerShell® script code from a number of lines
    linenumberstrue
    pwsh -NoLogo -NonInteractive -Command '& { `
      Echo "Hello"; `
      Echo "World"; `
    }'

    Explanation:

    • Note the use of single quotes, double quotes and semicolons as in the previous example. 
    • In addition each line of script code has to be terminated with a backtick for line continuation.
  • Last but not least In addition, a PowerShell® script can be executed from a file that has to be located by the executing is in reach of the JS7 Agent:

    Code Block
    languagebash
    titleExample how to run PowerShell® script code from a file
    linenumberstrue
    pwsh -NoLogo -NonInteractive -File some_powershell_script.ps1

...

  • As a bad alternative the PowerShell® executable can be invoked directly and can be parameterized like this:

    Code Block
    languagebash
    titleExample how to run PowerShell® script code from a single line
    linenumberstrue
    pwsh.exe -NoLogo -NonInteractive -Command "& { Echo ""Flight Destination: $env:FLIGHT_DESTINATION""; Echo ""Booking Code: $env:BOOKING_CODE""; }"

    Explanation:

    • Consider the quoting: when using the -Command parameter then the PowerShell® script has to be specified from a string. This includes:
      • quoting the script by double quotes.
      • quoting code inside the script with two double quotes or using single quotes.
    • Note that each PowerShell® command has to be terminated with a semicolon.


  • Last but not least In addition, a PowerShell® script can be executed from a file that has to be located by the executing is located in reach of the JS7 Agent:

    Code Block
    languagebash
    titleExample how to run PowerShell® script code from a file
    linenumberstrue
    pwsh.exe -NoLogo -NonInteractive -File some_powershell_script.ps1

...