Versions Compared

Key

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

...

  • Last but not least a PowerShell® script can be executed from a file that has to be located by the executing Agent:

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

Windows

The pwsh.exe process is the new name for PowerShell Core starting with version 6.0. The executable changed names from powershell.exe to pwsh.exe. Therefore if using a version < 6.0 please change pwsh.exe to powershell.exe

e.g. @@findstr/v "^@@f.*&" "%~f0"|powershell.exe -&goto:eof

  • Find the below examples for download (.json upload)run-powershell-windows.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
    languagebash
    titleExample how run PowerShell® script code with a shebang replacement
    linenumberstrue
    @@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 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 executable powershell.exe that can be used with the shebang accordingly.

...