PowerTip: Return a status code to Linux from PowerShell

The Scripting Guys

Dr Scripto

Summary: Pass a result code back to a calling Linux environment from Open Source PowerShell.

Hey, Scripting Guy! Question How can I pass a numeric value back to a calling Bash Shell to indicate an error?

Hey, Scripting Guy! Answer Just simply supply the EXIT command and a numeric value at the point where the error is flagged. For example, the following code is a PowerShell script that returns a value of 76 if the script does not match the value of $Value.

If ($Value -eq ‘Something Good’)
{
Write-Output ‘It’s Good, it’s very Good’
}
Else
{
Exist 76
}

The Doctor

The Scripting Guys
Dr Scripto

Follow Dr Scripto   

No Comments.