PowerTip: Capture error code of a PowerShell session in Linux or macOS
Summary: Capture the status code of a PowerShell session in Linux or macOS.
Could you show me how to run a PowerShell script in Linux or macOS and capture the status of whether that script succeeded or failed?
No problem, my friend. Just run the PowerShell session, and start the script as in the following example. You can view the status in the
$? built-in variable in Linux and macOS.
powershell -file ./samplescript.ps1