Tableau natively supports sending dashboards to users through a subscription model. There are two downsides to this: (1) the recipient must have a Tableau license and (2) the dashboard is sent in the body of the email. It has been my experience that a significant portion of end users in my production environment prefer to have the dashboard as an attachment. Tableau has created a useful and powerful cmdlet tool to assist in managing a Tableau environment. Part of this cmdlets functionality will allow dashboards to be sent via PDF. Here’s one strategy to create and deploy PDF dashboard emails.
Here's What You'll Need
- The Tableau cmdlet tabcmd
- The script
Preparing Your System
Before you begin, think about your current environment, and where it might make sense to have this script live and run. For example, in my production environment, the scripts are stored on our Tableau server. I can update, modify, and change the Windows Task Scheduler and the PowerShell script directly from logging into that server. If you develop and modify the script on a local machine, but deploy to a remote server (recommended), you’ll need to ensure that the following is setup on each machine.
Tabcmd is required for the script to work and can be downloaded directly from Tableau here. The process is pretty straight forward and will require that the correct version is installed alongside the server installation. I'm assuming you're familiar enough with your Tableau deployment environment that you can handle this without a detailed walk through, besides, it's not the fun part of this post.
Add tabcmd to Windows Path
Adding custom trusted 3rd party cmdlets to the Windows path is good practice, as it allows for a more native and interactive environment when working in the command line, but your mileage may vary. For the purpose of following along with this example, let’s assume it’s a requirement. You can follow this article from HowToGeek.com, and I've provided a quick summary below.
Open the Systems Properties windows by searching Windows for "Advanced System Settings" and clicking on Environment Variables. On the next window, shown above, select Path and click Edit on the bottom portion of Environment Variables window.
Just add the path to wherever you installed the cmdlet, as shown below, and you'll be good to use tabcmd in the command line just as you can any other native commands.
Modify the Script to Fit Your Needs
Let's take a look inside the EmailTableauDashboardScript folder:
There are three important files here. The script, tabEmailExtract.ps1, contains the logic and shouldn't need any changes. config.xml and list.csv will need modifications.
- list.csv stores the name and email address of everyone who should receive the email.
- config.xml contains the variables unique to your dashboard and server environment.
- Follow the comments in the code to make the appropriate changes from the default. Once changes are made to the <server>, <username>, <password>, and <mail> tags you're all set. Each additional deployment will only require that the exported filename be changed and the workbook/view directory on your Tableau server.
Note: After the inital setup of the xml and .csv document, I then create a new copy of the directory for use as a 'template' for additional dashboards. Each new dashboard which needs to be emailed I copy the folder, rename to the dashboard, and make changes to the xml and csv files. Depending on the deployment scale at your organization, this may or may not be ideal.
Scheduling Script with Windows Task Scheduler
To automate the delivery of this script, I have Windows Task Scheduler take care of executing when desired. I assume you know how Task Scheduler works and will be able to get it working in your environment.
Set your action like the example below.
-NoProfile -Executionpolicy bypass -file "C:\PowerShellScripts\PaperDailyDashboard\tabEmailExtract.ps1"
Add the string above, replacing the directory structure for your use case, and define the start as the parent folder.
It's important to understand that this isn't PowerShell but the command prompt. Take the string to execute the command and break it up into the program and arguments.
That covers all of the high-level areas required to get this script functioning correctly in your environment. The provided code has some pretty detailed documentation and should walk you through the thought process.