Terminating a script in PowerShell

前端 未结 10 1893
走了就别回头了
走了就别回头了 2020-11-28 01:02

I\'ve been looking for a way to terminate a PowerShell (PS1) script when an unrecoverable error occurs within a function. For example:

function foo() {
    #         


        
10条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-28 01:10

    Terminates this process and gives the underlying operating system the specified exit code.

    https://msdn.microsoft.com/en-us/library/system.environment.exit%28v=vs.110%29.aspx

    [Environment]::Exit(1)

    This will allow you to exit with a specific exit code, that can be picked up from the caller.

提交回复
热议问题