PowerShell Command
The pwsh command executes PowerShell scripts with full environment control and configurable exit code handling. It works on Windows, Linux, and macOS.
Attributes
Required
type: "pwsh": Identifies this as a PowerShell commandname: Descriptive name for the commandscriptORscript_file: PowerShell script content or path to script file (mutually exclusive)
Optional
working_directory: Directory to execute the command inenv: Environment variables as key-value pairsruns_on_condition: When to run (success,error,always,exit-codes)runs_on_exit_codes: Specific exit codes that trigger executionsuccess_exit_codes: Exit codes indicating success (defaults to[0])skip_exit_codes: Exit codes that skip remaining commands
Inline Script Example
Script File Example
Complete Example
Script vs Script File
Use script for inline PowerShell code:
Use script_file to reference an external file:
Note: script and script_file are mutually exclusive. Use one or the other.
Exit Code Handling
PowerShell exit codes work the same as shell commands:
Best Practices
- Use Write-Host for output: Makes messages visible in Porch results
- Check $LASTEXITCODE: Verify exit codes of called commands
- Set working directory: Use
working_directoryattribute instead of Set-Location - Use environment variables: Access via
envattribute, read with$env:VAR_NAME - Handle errors: Use
exitto return appropriate codes
Related
- Shell Command - Execute shell commands
- Flow Control - Conditional execution and error handling