Classically, programs in MS-DOS and under the Windows Command Line (CMD.EXE) signalled errors by setting the system environment variable ERRORLEVEL
to a non-zero value. PowerShell does not, by default, do this. If one wishes to invoke a PowerShell script, and have it behave like other programs (and batch files) when called from a batch file, the call to [Environment]::Exit()
allows you to set ERRORLEVEL
in a way that is compatible with CMD.EXE’s expectations. You can see more about [Environment]::Exit()
at Microsoft Docs.
4
solved [Environment]::Exit(0) – MEANING OF THIS? [closed]