Windows PowerShell Exit Codes

Windows PowerShell Exit Codes

 

PSMDTAG:FAQ: How can my script control the PowerShell exit code?

Answers:

  1. A normal termination will set the exitcode to 0
  2. An uncaught THROW will set the exitcode to 1
  3. The EXIT statement will stop the process and set the exitcode to whatever is specified.

 

c:\>powershell -noprofile -command "Write-output Test"
Test

c:\>echo %errorlevel%
0

c:\>powershell -noprofile -command "Write-output Test; throw 'ERROR'"
Test
ERROR
At line:1 char:25
+ Write-output Test; throw  <<<< 'ERROR'

c:\>echo %errorlevel%
1

c:\>powershell -noprofile -command "Write-output Test; exit 31492"
Test

c:\>echo %errorlevel%
31492

 

Jeffrey Snover [MSFT]
Windows PowerShell/MMC Architect
Visit the Windows PowerShell Team blog at:    http://blogs.msdn.com/PowerShell
Visit the Windows PowerShell ScriptCenter at
http://www.microsoft.com/technet/scriptcenter/hubs/msh.mspx

转载于:https://www.cnblogs.com/hualiu0/p/5105281.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值