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

The Scripting Guys

Dr 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

The Scripting Guys
Dr Scripto

Follow Dr Scripto   

No Comments.