Wednesday, March 12, 2014

PowerShell and Tableau Server: Automating User Creation and Group Population

UPDATE: I corrected the link to enable secure password storage and recovery in PowerShell.  Apologies for the incorrect link.

As long as Tableau Server runs on Windows machines, an admin's best friend is to leverage PowerShell to automate some everyday tasks.  There have been other great articles on combining Tableau and PowerShell, like Automated PDF Email Distribution by the talented folks at +InterWorks.  

But what, for whatever reason, you need to take down a Tableau Server configured for Active Directory Authentication, restore it as Local Authentication, and recreate the existing users (because the users from a directory will not translate to local authentication).  

Why it just so happens that I have a sample script for that!  To do this, you will need the following items
  • An admin login and password for Tableau server 
  • A csv file with the existing users, their names, and potentially email address'
  • A csv file with the groups and their users
    • Both csv's can be generated using data from the PostgreSQL.  Read here for how to enable that (and search the forums for how to enable read access for all tables/views, not just the default ones!!!)
  • A will and desire to WIN! or just take an otherwise tedious task off your plate.
CLICK HERE for a working powershell script and sample documents.  This method stores the password in the script, though there is a secure method of accomplishing this listed here.

KEY TAKEAWAYS FOR POWERSHELL
Import-CSV: A very power cmdlet to read data from a csv and allow the script to 'play with the results'
select-object: Manipulate the results of a data set (perhaps coming from Import-CSV), much like you would with SQL
.\: This forces PowerShell to run traditional command prompt commands without prompting the user to accept it
foreach: Exact what the name suggests, iterate through every line of a dataset and run a series of commands

Thanks everyone.  Take care and let me know if you have any questions.