Terminating a script in PowerShell

前端 未结 10 1868
走了就别回头了
走了就别回头了 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:15

    Exit will exit PowerShell too. If you wish to "break" out of just the current function or script - use Break :)

    If ($Breakout -eq $true)
    {
         Write-Host "Break Out!"
         Break
    }
    ElseIf ($Breakout -eq $false)
    {
         Write-Host "No Breakout for you!"
    }
    Else
    {
        Write-Host "Breakout wasn't defined..."
    }
    

提交回复
热议问题