Use PowerShell to download all your Power BI reports from a workspace

You can use PowerShell to download all of your PBI reports in a workspace all at once without having to go through the PBI service UI one at a time. As an added bonus, you may notice that downloading a report with PowerShell is faster that downloading it through the PBI Service UI.

This script is useful for admins to take backups of reports deployed to PBI Service. It can be easily extended to loop through all/several workspaces. It is also useful for developers to take a backup of their report before publishing a new version.

<#
 This script downloads all Power BI Reports in a workspace.
 It adds today's date to the beginning of the file name to make it 
 easier to take daily backups.
 2020-10-12
 ABI Cube corp.
>#


<#
  This script requires the MicrosoftPowerBIMgmt module.
  Run the following command to install it if not already installed: 
  Install-Module -Name MicrosoftPowerBIMgmt 
#>

<#If the login step to PBI fails, try running the following line first.
 [Net.ServicePointManager]:SecurityProtocol = [Net.SecurityProtocolType]::Tsl12
#>

#Log in to Power BI Service
Login-PowerBI  -Environment Public

$PBIWorkspace = Get-PowerBIWorkspace -Name 'My Workspace Name'

$PBIReports = Get-PowerBIReport -WorkspaceId $PBIWorkspace.Id # -Name "My Report Name" #Use the Name parameter to limit to one report.

$TodaysDate = Get-Date -Format "MM_dd_yyyy_"

$OutPutPath = "C:\PowerBIReportsBackup\" + $TodaysDate 

#Loop through the reports:
ForEach($Report in $PBIReports)
{
 Write-Host "Downloading " $Report.name 
 $OutputFile = $OutPutPath +  $Report.name + ".pbix"

 # If the file exists, delete it first; otherwise, the Export-PowerBIReport will fail.
 if (Test-Path $OutputFile)
 {
     Remove-Item $OutputFile
 }

 Export-PowerBIReport -WorkspaceId $PBIWorkspace.ID -Id $Report.ID -OutFile $OutputFile

}

The following image shows the output for one of my workspaces:

This is how the output folder look like:

One thought on “Use PowerShell to download all your Power BI reports from a workspace

Leave a Reply