Exporting all your Power BI reports at once

A few weeks ago one of my colleagues showed me a PowerShell script to export all Power BI reports from a Power BI Workspace. This could come in handy for back-up purposes (version control is still hard to accomplish) or if you don’t have access to the PBIX files via the normal way and you need to do some edits. The original file can be found here.

I made some changes to the original file to download all reports, from all workspaces and put them in a nice folder structure, with the same names as your workspaces. Of course, it’s still possible to limit the download to only one workspace and one report. Here we go.


#Log in to Power BI Service
Login-PowerBI -Environment Public
#First, Collect all (or one) of the workspaces in a parameter called PBIWorkspace
$PBIWorkspace = Get-PowerBIWorkspace # Collect all workspaces you have access to
#$PBIWorkspace = Get-PowerBIWorkspace -Name 'My Workspace Name' # Use the -Name parameter to limit to one workspace
#Now collect todays date
$TodaysDate = Get-Date -Format "yyyyMMdd"
#Almost finished: Build the outputpath. This Outputpath creates a news map, based on todays date
$OutPutPath = "C:\PowerBIReportsBackup\" + $TodaysDate
#Now loop through the workspaces, hence the ForEach
ForEach($Workspace in $PBIWorkspace)
{
#For all workspaces there is a new Folder destination: Outputpath + Workspacename
$Folder = $OutPutPath + "\" + $Workspace.name
#If the folder doens't exists, it will be created.
If(!(Test-Path $Folder))
{
New-Item -ItemType Directory -Force -Path $Folder
}
#At this point, there is a folder structure with a folder for all your workspaces
#Collect all (or one) of the reports from one or all workspaces
$PBIReports = Get-PowerBIReport -WorkspaceId $Workspace.Id # Collect all reports from the workspace we selected.
#$PBIReports = Get-PowerBIReport -WorkspaceId $Workspace.Id -Name "My Report Name" # Use the -Name parameter to limit to one report
#Now loop through these reports:
ForEach($Report in $PBIReports)
{
#Your PowerShell comandline will say Downloading Workspacename Reportname
Write-Host "Downloading "$Workspace.name":" $Report.name
#The final collection including folder structure + file name is created.
$OutputFile = $OutPutPath + "\" + $Workspace.name + "\" + $Report.name + ".pbix"
# If the file exists, delete it first; otherwise, the Export-PowerBIReport will fail.
if (Test-Path $OutputFile)
{
Remove-Item $OutputFile
}
#The pbix is now really getting downloaded
Export-PowerBIReport -WorkspaceId $Workspace.ID -Id $Report.ID -OutFile $OutputFile
}
}

With the comments inside the script, I already explain step-by-step how it works. Now I just add some screenshots to show whats happening!

First I’m asked to sign into Power BI
First I’m asked to sign into Power BI
PowerShell replies with my Tenant Information
PowerShell replies with my Tenant Information
Continuing with the code
Continuing with the code

As you can see in the picture above, I decided to download all my reports, from all my workspaces. Some reports aren’t available for download, for example, when incremental refresh is enabled. So far I’ve encountered the following operation failures: Forbidden, BadRequest, NotFound and Unauthorized. The incremental refresh report gave me a BadRequest, and two Usage Metrics report, which I didn’t create, were NotFound. Makes sense, but I’m not sure how they got indexed in the first place. The Unauthorized one is a Microsoft 365 Usage Analytics report. That’s an app from AppSource and while writing this article, you aren’t able to download these pbix files. Now the Forbidden one. I’ts a copy of an incremental refresh dataset, and has no data inside. I’m not completely sure how I got it there in the first place. But that there is something wrong with it, that’s for sure ;).

Here you can see the results of the final step of the script:

Downloading notification in PowerShell
Downloading notification in PowerShell

And here is my folder structure. As you can see I ran it on the 29th of January and the first of February:

Folder structure in Explorer
Folder structure in Explorer

I really hope this script will come in handy for those who need it! With the different options to download All reports, from all workspaces or all reports in one workspace or one report in one workspace, you have a lot of freedom to adjust it to your needs!

Take care.

Categories Power BI, PowerShell

18 thoughts on “Exporting all your Power BI reports at once

  1. This is super helpful. I am getting a timeout error for a couple of the dashboards though. I need to find some way to set the timeout.

    Like

  2. It works like magic. I downloaded all 12 pbix within 15 min. while downloading them individually takes hours

    Like

  3. Only 1 out 82 report was not able to download using this script. This is awesome! Thank you!

    Like

  4. robbiefrancis 6 January 2023 — 12:15

    This is really useful – Thank You! I do have a question – is there a way to filter out reports that include datasets, so I essentially leave the bigger models, and only backup the reports?

    Like

  5. This saved hours. Thank you so much!

    Liked by 1 person

  6. Amazing, thank you, very useful!

    Like

  7. sandeep singh verma 13 June 2023 — 15:10

    I want to migrate one report from one workspace to multiple workspaces in power bi. Could you please post the power shell script for this.

    Like

    1. Hi Sandeep Singh Verma,

      I’m not really an expert on the PowerShell Cmdlets, but you can try to modify this one:
      https://learn.microsoft.com/en-us/powershell/module/microsoftpowerbimgmt.reports/copy-powerbireport?view=powerbi-ps

      I hope this helps!

      Like

  8. This is a great tool that I had been using until it got accidently deleted. Trying to get it working again and I’m having an issue where it’s erroring on “Report Usage Metrics Report” that doesn’t exist in the workspace. I can’t figure out how to filter it out nor can I figure out how to make the download ignore errors and continue. Any suggestions?

    Export-PowerBIReport : Operation returned an invalid status code ‘NotFound’
    At line:72 char:4
    + Export-PowerBIReport –WorkspaceId $Workspace.ID –Id $Repo …
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : WriteError: (Microsoft.Power…rtPowerBIReport:ExportPowerBIReport) [Export-PowerBIReport], HttpOperationException
    + FullyQualifiedErrorId : Operation returned an invalid status code ‘NotFound’,Microsoft.PowerBI.Commands.Reports.ExportPowerBIReport

    Like

    1. I’m sorry Jim,
      As mentioned below, I’m not a real expert on the PowerShell part. The script that I posted continues whenever it can’t find a file.

      Like

      1. Thanks Erik. Shortly after I posted that message, I found a fix, but couldn’t edit or delete my comment. If anyone else has that issue, you need to add -ErrorAction Ignore at the end of the line that starts with Export-PowerBIReport

        Liked by 1 person

  9. Great post, thank you! What is the permission required to download files? Does any user with Pro license can download? Thank you.

    Like

    1. Hi Anusha,

      You need to have access to the workspace and have at least contributer role. So actually the same as downloading a file from the workspace manually.

      Like

  10. Hi,

    Great post, very helpful.

    Any idea how to adapt the code to download PBIP files rather than PBIX?

    Thanks

    Like

  11. The key player in this process is a little magic called PowerShell. The article provides a handy script you can adapt to your needs. It basically retrieves all reports from your chosen workspace and downloads them as PBIX files (the native Power BI file format).

    Like

  12. Richard Appleton 9 January 2024 — 17:18

    Hi Erik, this is great thank you. Do you know if you are able to download the semantic models using a similar script? I have checked the Microsoft Documentation for Power Shell and Power BI and there doesn’t appear to be an option. Just wondered if anyone knew if this was possible?
    Thanks a lot,
    Richard

    Like

    1. Hi Richard,
      As far as my knowledge goes, I don’t think you can. If you are on a Premium/Fabric WS, you can however use external tools to connect to that model.

      Best regards,
      Erik

      Liked by 1 person

      1. richardappleton95ec726d5d 29 January 2024 — 12:38

        Thanks a lot, Erik

        Liked by 1 person

Leave a comment