6 Replies Latest reply on Mar 23, 2015 11:32 AM by dholdandnotused

    capturing tabcmd output in powershell

    Bo Altes

      I'm trying to put together a Powershell script for publishing workbooks. I'd like to handle and log tabcmd errors. I'm intentionally sending a login command through Powershell that will fail. Using only tabcmd, the Powershell session looks like this:


      PS C:\> tabcmd login -s $server -u $user -p $pass

      ===== Creating new session

      =====     Server:   http://www.badexample.com

      =====     Username: user

      ===== Connecting to server...

        *** initialize: name or service not known


      If I use Invoke-Expression and try to capture the output in a variable with a pipe or redirect, I'm only getting the first four lines and not the actual result of tabcmd. I'd like to capture all of the output, but haven't figured out how to write the last line ("*** initialize: name or service not known") to a variable. Standard error doesn't work because the system command I'm calling has completed without returning an error to Powershell.


      As an example of what I'm using in Powershell, this only captures the first four lines, but not the error:


      $output = Invoke-Expression "tabcmd login -s $server -u $user -p $pass"|Out-String


      This gives the same results as Invoke-Expression:


      $output = tabcmd login -s $server -u $user -p $pass


      Has anyone dealt with this before?