I'm writing a PS script to update my tfs workspace. However, Update-TfsWorkspace doesn't throw an exception when it fails. e.g. when the user doesn't have permission to write the workspace, or the workspace cannot be determined. It only displays the message on the console. I assume it's on stderr. If I run the script and redirect like "2>logfile", I can see the message in logfile. However, if I call the cmdlet using this syntax:
Update-TfsWorkspace C:\DoesNotExist 2> logfile
It doesn't work. The error message is not in logfile, but rather output on the console. What's the best way to capture the error from this cmdlet so that I can determine the action upon a failure?
Thanks!