PowerShell: return error exit code if not match a string
powershell
Solution
In an script you can change exit code using `exit` keyword.
A normal termination will set the exitcode to 0
An uncaught `THROW` will set the exitcode to 1
The `EXIT` statement will stop the process and set the exitcode to whatever is specified.
In your case I'ld do something like this
if ( $(hostname) -eq 'mycomputername')
{
exit 0
}
else
{
exit 1
}
Problem
I found that `$(Invoke-Expression hostname) -eq 'mycomputername'` Whether it is matched or not, the exitcode must be 0 this behavior is different from linux ,i.e, if not match error code exit 1 Is there any short command in PowerShell that can return error exit code if doesn't match the string?