Page History
...
- Find the below examples for download (.json upload): pdRunPowerShell4Windows.workflow.json
In order to directly run PowerShell® script code from a JS7 shell job script the recommended approach is to use a shebang replacement like this:
Code Block language bash title Example how run PowerShell® script code with a shebang replacement linenumbers true @@setlocal enabledelayedexpansion & set f=%RANDOM%.ps1 & @@findstr/v "^@@[fs].*&" "%~f0" | > !f! & powershell.exe -NonInteractive -Command -File !f! & set e=!errorlevel! & del /q !f! & exit !errorlevele!/b& Write-Output "Hello" Write-Output "world"
Explanation:
- If you consider this shebang replacement somewhat cryptic then add it to JS7 - Script Includes which are easily referenced from shell jobs, e.g. by using
##!include pwsh
- The PowerShell®
pwsh.exe
executable is available starting with PowerShell 6.0. PowerShell releases 5.x use the executablepowershell.exe
that can be used with the shebang accordingly.Therefore if when using a version > 5.1 please change powershell.exe to pwsh.exe:
|@@setlocal enabledelayedexpansion & set f=%RANDOM%.ps1 & @@findstr/v "^@@[fs].*&" "%~f0"
-Command - & exit !errorlevel> !f! & pwsh.exe -NonInteractive
-File !f! & set e=!errorlevel! & del /q !f! & exit !e!/b&
- If you consider this shebang replacement somewhat cryptic then add it to JS7 - Script Includes which are easily referenced from shell jobs, e.g. by using
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 run PowerShell® script code from a single line linenumbers true 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.
- Consider the quoting: when using the
...
Overview
Content Tools