1 Reply Latest reply on Feb 26, 2014 9:05 AM by Travis Boyle

    Handy Powershell snippet

    Travis Boyle

      I've been working on a way to ensure the correct path to the tableau command line tools is set in the path environment variable, to make my powershell scripts more portable (no need to either pre-set the %path% or customize the script to match the server's configuration).  What I've come up with at this point is:

       

      $tabCmdLoc = get-command tabcmd.exe | select-object -expandProperty definition

      $tabCmdPath = $tabCmdLoc.Substring(0,$tabCmdLoc.Length-10)

      $env:path = $env:path + ";$tabCmdPath"


      if (!($env:path.Contains("Tableau Server"))){

        if (test-path "C:\Program Files\Tableau\Tableau Server\8.1\extras\Command Line Utility\tabcmd.exe"){

        $env:path = $env:path + ";C:\Program Files\Tableau\Tableau Server\8.1\extras\Command Line Utility\"

        }

        elseif (test-path "C:\Program Files\Tableau\Tableau Server\8.1\bin\tabcmd.exe"){

        $env:path = $env:path + ";C:\Program Files\Tableau\Tableau Server\8.1\bin\"

        }

        elseif (test-path "D:\Program Files\Tableau\Tableau Server\8.1\bin\tabcmd.exe"){

        $env:path = $env:path + ";D:\Program Files\Tableau\Tableau Server\8.1\bin\"

        }

        elseif (test-path "C:\Program Files (x86)\Tableau\Tableau Server\8.1\bin\tabcmd.exe"){

        $env:path = $env:path + ";C:\Program Files (x86)\Tableau\Tableau Server\8.1\bin\"

        }

        elseif (test-path "D:\Program Files (x86)\Tableau\Tableau Server\8.1\bin\tabcmd.exe"){

        $env:path = $env:path + ";D:\Program Files (x86)\Tableau\Tableau Server\8.1\bin\"

        }

      }

       

       

      Hope this is useful for others, and willing to take any suggestions to cleanup the script.

       

      Travis

       

      Message was edited by: Travis Boyle - posting the snippet that will actually work, but have to manually add a line for each new environment if not already accounted for.

        • 1. Re: Handy Powershell snippet
          Travis Boyle

          Apparently I'm not as clever as I'd thought - this only works if tabcmd.exe is already in the path, so writing a bit of script to add something to the path that has to already be there for it to function may not exactly be useful.

           

          Hoping to get an actual working version of this soon - will update here when I do.