Capturing Non-Standard Powershell CmdLet Output for Flow Control

后端 未结 3 834
粉色の甜心
粉色の甜心 2021-01-22 05:13

Currently trying to build a script utilizing cmdlets from the MS released \"Team Foundation Server Power Tools\" package.

I\'m attempting to flow command logic from the

3条回答
  •  长情又很酷
    2021-01-22 06:04

    Your problem here is that the cmdlet is writing an error (Non-Terminating Error), but not throwing an exception (Terminating Error). You can make it throw an exception by adding the ErrorAction parameter:

    trap{echo "fail"}
    update-tfsworkspace $workspace_path -recurse -version T -ErrorAction "Stop"
    

    This will cause the cmdlet to make all errors terminating (throwing an exception if it writes to the error stream).

提交回复
热议问题