2 Replies Latest reply on Aug 11, 2016 6:58 AM by Tracy Mixa

    Tabcmd refreshextracts using PowerShell

    Tracy Mixa

      I have PowerShell scripts set up to refresh extracts on our Tableau server.  These scripts are kicked off via our scheduling app, ASG ZENA, after its parent process completes.  I have had this working for awhile now, but I've had to edit the script to point to a different site (but still on the same server).  Now I receive an error saying "Cannot sign in because of missing arguments: --username,--certificate,--server".  As you can see in my script below, the information is provided during the 'login' process.  Can someone provide some insight?


      # Set Tableau Parameters
      $ErrorLevel = $LASTEXITCODE
      $user = 'username'
      $server = 'tableau.company.com'
      $site = 'company site'
      $project = 'project name'
      $datasource = 'data source name'
      $ZENA = 'ZENA task name'
      # Set Email Notification Parameters
      $PSEmailServer = 'mail.company.com'
      $NoReply = 'NoReplyTableau@company.com'
      $ToEmail = 'user@company.com'
      $TabAdmin = 'TableauAdmin@company.com'
      $SuccessSubject = $ZENA + '-' + $datasource + 'Refresh Completed Successfully'
      $FailureSubject = $ZENA + '-' + $datasource + 'Refresh Failed'
      $FBody = $datasource + ' failed to refresh.  Please contact TableauAdmin@company.com'
      # Read Secure Password from File and Return Plain Text
      function ConvertFrom-SecureToPlain {
      $TabcmdPassword = get-content 'D:\pathtopasswordfile\storedPassword.txt' | Convertto-SecureString
      $credential = new-object system.management.automation.pscredential($user,$TabcmdPassword)
      $TabcmdPassword = $credential.getnetworkcredential().password
      Return $TabcmdPassword    
      $TabcmdPassword = ConvertFrom-SecureToPlain
      # Set the Tabcmd Directory
      $TabCmd = "D:\Program Files\Tableau\Tableau Server\9.3\bin\tabcmd.exe"
      # Log into the Server and Site
      & $TabCmd login -s $server -t $site -u $user -p $TabcmdPassword --no-certcheck 
      # Refresh Relevant Extracts and Log Out
      & $TabCmd refreshextracts --project $project --datasource $datasource --synchronous --no-certcheck
      $ErrorLevel = $LASTEXITCODE
      & $TabCmd logout
      # Send Appropriate Failure or Success Email Based on LASTEXITCODE
      if ($ErrorLevel -eq 0)
       Send-MailMessage -From $NoReply -To $ToEmail -Subject $SuccessSubject
        exit 0
        Send-MailMessage -From $NoReply -To $ToEmail -Cc $TabAdmin -Subject $FailureSubject -Body $FBody
       exit 1
        • 1. Re: Tabcmd refreshextracts using PowerShell
          Dmitry Chirkov

          You should put all the arguments that can have spaces in quotes. ($site = 'company site')


          Also, generic script debugging advice: for every interesting call print it out to console before executing (i.e. Write-Host $TabCmd login -s $server -t $site -u $user -p $TabcmdPassword --no-certcheck) so you can then paste it directly into command line and see what's wrong.

          • 2. Re: Tabcmd refreshextracts using PowerShell
            Tracy Mixa

            You got me thinking when you mentioned the spaces.  My $site = 'company site' parameter was already in quotes so I didn't think that was the issue. Even though I knew it would fail, I put the $site parameter in quotes (-s '$site'), just to see what would happen.  Here is the result:


            ===== Creating new session
            =====    Server:  http://tableau.company.com
            =====    Username: user
            =====    Site:    $site
            ===== Connecting to the server...
            ===== Signing in...
            ===== Creating new session
            =====    Server:  http://tableau.company.com
            =====    Username: user
            =====    Site:    $site

              *** You are not a member of site '$site'. Select a SITEID from the following sites:


            NAME: Company Name
            SITEID: 'CompanyName'


            I was not aware that the tabcmd script actually uses the SITEID instead of the NAME.  I updated my script and changed my $site = 'Company Name' to $site = 'CompanyName' and it worked!