Page History
...
- Find the below examples for download: run-powershell-windows.workflow.json
In order to directly add PowerShell script code to a JS7 shell job script the recommended approach is to use a shebang replacement like this:
Code Block language bash title Example how use PowerShell script code with a shebang replacement @@findstr/v "^@@f.*&" "%~f0"|pwsh.exe -&goto:eof Write-Output "Hello" Write-Output "world"
Explanation:
- Credits for the shebang replacement to How to run a PowerShell script within a Windows batch file
- If you consider this shebang replacement somewhat cryptic then add it to JS7 - Script Includes that are easily referenced from a shell job, e.g. by using
##!include pwsh
- The PowerShell executable
pwsh.exe
is available starting from PowerShell 6.0. PowerShell releases 5.x use the executablepowershell.exe
that can be used accordingly with the shebang.
As a bad alternative the PowerShell executable can be invoked directly and can be parameterized like this
Code Block language bash title Example how to add PowerShell script code from a single line 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 to- quote the script by double quotes.
- quote code inside the script with two double quotes or to use single quotes.
- Consider that each PowerShell command has to be terminated with a semicolon.
- Consider the quoting: when using the
...
Overview
Content Tools