unix exit command equivalent in powershell? unix exit command equivalent in powershell? unix unix

unix exit command equivalent in powershell?


There is an exit [<code>] keyword in PowerShell. If you use exit in a script, it doesn't matter what scope you are in and even what nesting level, the script will exit. If you execute exit in the PowerShell console it will exit the PowerShell session. You can use the automatic variable $LastExitCode to see the value returned by exit.


Don't forget that PowerShell also has exceptions. It might be more appropriate to throw an exception when you encounter an error. That depends on the particulars of the scripts you are porting of course, but it's another tool in the toolbox you can use.