November 4th, 2016

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

Doctor Scripto
Scripter

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

Author

The "Scripting Guys" is a historical title passed from scripter to scripter. The current revision has morphed into our good friend Doctor Scripto who has been with us since the very beginning.

0 comments

Discussion are closed.