Terminating a script in PowerShell

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

    I used this for a reruning of a program. I don't know if it would help, but it is a simple if statement requiring only two different entry's. It worked in powershell for me.

    $rerun = Read-Host "Rerun report (y/n)?"
    
    if($rerun -eq "y") { Show-MemoryReport }
    if($rerun -eq "n") { Exit }
    

    Don't know if this helps, but i believe this would be along the lines of terminating a program after you have run it. However in this case, every defined input requires a listed and categorized output. You could also have the exit call up a new prompt line and terminate the program that way.

提交回复
热议问题