powershell遇到错误即推出的方法

$ErrorActionPreference = "Stop"; $tcpClient = new-object Net.Sockets.TcpClient; $tcpClient.Connect("fuat.xxx.com", 801); echo "success"

 

参考资料:

https://stackoverflow.com/questions/9948517/how-to-stop-a-powershell-script-on-the-first-error?noredirect=1

https://www.saotn.org/powershell-return-value-exit-code-or-errorlevel-equivalent/

https://4sysops.com/archives/stop-or-exit-a-powershell-script-when-it-errors/

https://segmentfault.com/a/1190000007727032

 

posted @ 2021-02-23 14:30  junneyang  阅读(190)  评论(0编辑  收藏  举报