Capturing Non-Standard Powershell CmdLet Output for Flow Control

后端 未结 3 829
粉色の甜心
粉色の甜心 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 05:38

    Little hacky, but since I don't have TFS to try to figure something else out, see if this helps.

    0 讨论(0)
  • 2021-01-22 05:50

    I would say that this cmdlet wasn't written correctly. First, since it didn't succeed it should have emitted an error object which would have caused $? to return false which you could have checked or trapped. Second, you can't suppress the error message using -ea 0. It looks like this snapin is using the Host api to write an error string to the host console. That's a spew!! For now, you could do what EBGreen suggests:

    $msg = powershell.exe -nologo update-tfsworkspace "C:\doesnotexist\" -recurse -version T 2>&1

    Just watch out for all the text your profile script spits out when a new instance of PowerShell starts up.

    0 讨论(0)
  • 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).

    0 讨论(0)
提交回复
热议问题