PowerTip: Capture error code of a PowerShell session in Linux or macOS

Doctor Scripto

Summary: Capture the status code of a PowerShell session in Linux or macOS.

Hey, Scripting Guy! Question 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?

Hey, Scripting Guy! Answer 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

echo $?

The Doctor

0 comments

Discussion is closed.

Feedback usabilla icon