As Power BI grows, we want to empower our users to focus their time and energy on gaining insights and acting on them in a timely manner. To that end, the Power BI team is committed to enabling users to easily automate important yet repeatable tasks. To reach our goal, we’ve continued to release powerful APIs in recent months that push the limits of what you can do with Power BI and automation.
In this tutorial, will show how you can use these powerful APIs to duplicate a workspace and all the dashboards, reports and datasets within. We’ve also provided a fully functioning PowerShell script so you can jump in and see it working right away.
We hope you will find this to be a powerful tool suitable for a variety of situations. Did you start with a My Workspace but now you want to collaborate on that content with others? Simply duplicate My Workspace to an app workspace. Want to publish two similar (but not identical) apps? Now you can build one app workspace, and then duplicate it and make the required tweaks on the copy. Now you have two apps.
How to: use the PowerShell script to duplicate a workspace
Let’s jump right in and see the script in action. The steps below guide you through using the PowerShell script to duplicate a workspace. It will work “out of the box” with minimal setup and coding experience required.
- Install PowerShell and the Azure PowerShell cmdlets
- Download the PowerShell script
- Next, you will need a AAD client ID – you can get this in a few easy clicks from our app registration portal. For app type, select native app. For redirect URI, you can enter
urn:ietf:wg:oauth:2.0:oob. Under API access, be sure to check all the boxes
- Take the client ID you received in the step above and paste it into line 3 of the script
- Run PowerShell as administrator and navigate to the directory where you downloaded the script
From there, the script is self-explanatory – simply enter the name of the workspace that you want to duplicate, and then enter the name of the new workspace which will host the duplicate content. And that’s it! The script will begin copying all the content from the source workspace to the target.
Read on to learn more about how the script, how it works, and to learn how you can customize the script to fit your own needs.
Deep-dive: how the script works
At a high-level, the script works in four steps. These steps are labeled as comments in the script, for those who want to follow along.
- Authentication: the script starts by using the Active Directory Authentication Library (ADAL) to authenticate you against AAD, acquiring an access token for use in all web requests
- Export/Import PBIX files: to copy datasets between workspaces, it uses the export and import PBIX APIs. First, the script gets the list of reports in the source workspace using the get reports API. Then, it exports the PBIXes for those reports from the source workspace, and then imports the PBIX into the target workspace. This copies over the report and its associated dataset.
- Clone report files: If we have multiple reports built on the same dataset, then exporting and importing the PBIX for each report will result in duplicate datasets. As a result, we make sure to only export one PBIX per dataset. For the rest of the reports built on the dataset, we call the clone reports API to copy the rest of the reports
- Copying dashboards: to copy the dashboards, we first use the get dashboards API to get the list of dashboards in the source workspace. Then, we use the add dashboard API to create dashboards in the target workspace, and then the clone tile APIs to copy the tiles from the source to target dashboard, one tile at a time
Note that as-is, this script has some limitations.
- Since we use the export and import PBIX APIs to copy datasets, we can only copy the datasets that were built in Power BI Desktop – i.e. streaming datasets, samples, etc., cannot be copied
- You must have edit permissions on the source workspace, since edit permissions are required for export PBIX
- This script won’t copy over refresh schedules, alerts, subscriptions, or workspace memberships – those will have to be manually recreated on the target workspace
- Take the PowerShell script for a spin. With the instructions above, you should be able to get started in minutes
- Have comments or questions about the script, REST APIs, or anything else Power BI-related? We’d love to hear from you. Please leave comments below or in the community forums
- Feel free to repurpose the sample script for your own use. Found a bug or have an improvement for the existing script? Feel free to create a pull request on Github
- Read more about the Power BI REST APIs, and about app workspaces