2 Replies Latest reply on Sep 13, 2018 7:03 AM by Suman Manu

    How to catch TSM error messages in PowerShell?

    Aron Saläng

      Hi

       

      I have a maintenance script in PowerShell that handles weekly backup and cleanup on a Tableau Server (2018.2).

       

      It's working fine and I use $LastExitCode to verify that commands finish correctly.

      What I haven't been able to do is to get details on any error that occurs.

       

      Here's a sample code that creates an error and tries display it in a popup window:

       

      $TSMcmd = ".\tsm maintenance cleanup -x"

      Invoke-Expression -Command:$TSMcmd

          if($LastExitCode -eq 1)

          {

                [System.Windows.Forms.MessageBox]::Show($Error[0]) 

           }

       

      There's no -x option for the tsm maintenance command so the console shows: "Unrecognized option: -x".

      I can catch the error with if($LastExitCode -eq 1) but I don't know to get the details of it. I've tried to use the $Error object but that doesn't work.

       

      Anybody have a suggestion on how to do this? Nota bene that displaying a popup window with the error message is not the end game. I will write it in an email notification once I get it to work.

       

      Any help would be greatly appreciated.

      /Aron