How to Download All Your SSRS Report Definitions (RDL files) Using PowerShell

Here’s a short PowerShell script that :
1. Connects to your report server
2. Creates the same folder structure you have in your Report Server
3. Download all the SSRS Report Definition (RDL) files into their respective folders

In addition to backing up your Source Project, your ReportServer database, or good old RSScripter (see http://sqlserver-indo.org/blogs/mca/archive/2009/03/08/extract-and-transfer-rdl-files-from-ssrs.aspx) this is just another way you can “backup” or archive your reports.

#note this is tested on PowerShell v2 and SSRS 2008 R2
[void][System.Reflection.Assembly]::LoadWithPartialName("System.Xml.XmlDocument");
[void][System.Reflection.Assembly]::LoadWithPartialName("System.IO");

$ReportServerUri = "http://yourreportserver/ReportServer/ReportService2005.asmx";
$Proxy = New-WebServiceProxy -Uri $ReportServerUri -Namespace SSRS.ReportingService2005 -UseDefaultCredential ;

#check out all members of $Proxy
#$Proxy | Get-Member
#http://msdn.microsoft.com/en-us/library/aa225878(v=SQL.80).aspx

#second parameter means recursive
$items = $Proxy.ListChildren("/", $true) | `
         select Type, Path, ID, Name | `
         Where-Object {$_.type -eq "Report"};

#create a new folder where we will save the files
#PowerShell datetime format codes http://technet.microsoft.com/en-us/library/ee692801.aspx

#create a timestamped folder, format similar to 2011-Mar-28-0850PM
$folderName = Get-Date -format "yyyy-MMM-dd-hhmmtt";
$fullFolderName = "C:Temp" + $folderName;
[System.IO.Directory]::CreateDirectory($fullFolderName) | out-null

foreach($item in $items)
{
    #need to figure out if it has a folder name
    $subfolderName = split-path $item.Path;
    $reportName = split-path $item.Path -Leaf;
    $fullSubfolderName = $fullFolderName + $subfolderName;
    if(-not(Test-Path $fullSubfolderName))
    {
        #note this will create the full folder hierarchy
        [System.IO.Directory]::CreateDirectory($fullSubfolderName) | out-null
    }
    
    $rdlFile = New-Object System.Xml.XmlDocument;
    [byte[]] $reportDefinition = $null;
    $reportDefinition = $Proxy.GetReportDefinition($item.Path);
    
    #note here we're forcing the actual definition to be 
    #stored as a byte array
    #if you take out the @() from the MemoryStream constructor, you'll 
    #get an error
    [System.IO.MemoryStream] $memStream = New-Object System.IO.MemoryStream(@(,$reportDefinition));
    $rdlFile.Load($memStream);
    
    $fullReportFileName = $fullSubfolderName + "" + $item.Name +  ".rdl";
    #Write-Host $fullReportFileName;
    $rdlFile.Save( $fullReportFileName);

}

Enjoy!

29 thoughts on “How to Download All Your SSRS Report Definitions (RDL files) Using PowerShell

  1. Marios Philippopoulos June 10, 2011 / 1:13 pm

    I’m getting this error when running this script against both a SQL-2005 and a SQL-2008 SSRS instance:

    The term ‘New-WebServiceProxy’ is not recognized as the name of a cmdlet, funct
    ion, script file, or operable program. Check the spelling of the name, or if a
    path was included, verify that the path is correct and try again.

    My $ReportServerUri is defined correctly.

    What could I be missing?

    Thank you,
    Marios Philippopoulos

    Like

  2. Geoff September 27, 2011 / 12:33 pm

    This worked perfectly. You saved me at least a day of file->save-as’ing – thanks a million!!!

    Like

  3. Aman December 7, 2011 / 5:37 am

    how could i pass the authentication(username, pass)?
    if i’m going to download from remote computer.

    Thanks B4.

    Like

  4. Ed February 22, 2012 / 12:28 pm

    I am also getting the error below.

    The term ‘New-WebServiceProxy’ is not recognized as the name of a cmdlet, funct
    ion, script file, or operable program. Check the spelling of the name, or if a
    path was included, verify that the path is correct and try again.

    Any thoughts as to what might be wrong?

    Like

    • belle March 10, 2012 / 2:03 pm

      What version of PowerShell are you using?

      Like

  5. Edgar September 5, 2012 / 10:48 am

    you are a life saver
    🙂

    Like

  6. BadCoder September 17, 2012 / 12:26 pm

    Worked perfectly.. Thanks so much.

    Like

  7. Jigz February 17, 2013 / 10:38 pm

    Hello,

    $Proxy = New-WebServiceProxy -Uri $ReportServerUri -Namespace SSRS.ReportingService2005 -UseDefaultCredential ;

    May I know what is the instance name use on this line? I’m referring with SSRS.ReportingService2005.

    Like

  8. mohan March 21, 2013 / 2:52 am

    Excellent….really useful
    Can we do the for upload instead of download.

    Like

  9. mohan March 21, 2013 / 2:52 am

    Excellent….really useful
    Can we do the same for upload instead of download.

    Like

  10. Smally May 14, 2013 / 7:51 am

    How can i do the same with rds ?
    Because i need to save DataSource too.

    Like

  11. Ren October 24, 2013 / 10:11 pm

    nice Work :D…it worked perfectly…

    Like

  12. Arun Saxena January 14, 2014 / 6:05 am

    Amazing! Works like Knife on Butter..

    TY

    Like

  13. Prashant Gaikwad March 5, 2014 / 1:32 am

    Worked for me on SSRS 2012. Is it possible to download a single folder, because this script downloads everything on the report server.

    Like

  14. Anonymous March 20, 2014 / 10:44 am

    Couple things if you are using SSRS2008 R2; It really uses 2010 so ReportService2005.asmx should be ReportService2010.asmx. Also, you want to use -Namespace SSRS.ReportingService2010 instead.

    RS2010 also uses $Proxy.GetItemDefinition($item.Path); instead.

    Like

  15. Prashant Gaikwad April 23, 2014 / 12:21 am

    Can you please provide a script to upload all the folders back to report server.

    Like

  16. John McAulay May 29, 2014 / 8:11 am

    Thanks so much! Fantastic script.

    Like

  17. David R June 20, 2014 / 10:38 am

    Sorry, I’m a newbie when it comes to PowerShell… how to I run this script?

    Can you provide detail instructions for those of us who are not familiar with PowerShell?

    Like

  18. SomeDude July 2, 2014 / 7:59 am

    For those who run into a webserviceproxy error, I had the problem as well initially. I hadn’t realized that the “/ReportService2005.asmx” path on the end of my report server URL was important and had not included it at first; particularly because I am SSRS 2008 R2.

    In any case, add that /ReportService2005.asmx back on if you took it off and that might help.

    Like

  19. Samuel Lopez August 27, 2014 / 11:06 am

    thanks a lot, it was so helpfull this article and the solution too!

    The wired thing, was that i migrated time ago from 2005 to 2008, and I changed the code for the $ReportServerUri = “http://my server/ReportServer/ReportService2005.asmx”;

    ReportService2008.asmx and didn’t work but i left has you have it with 2005 and works.

    Like

  20. wordpressuser February 6, 2017 / 9:41 am

    How can I backup the report along with the subscriptions is there any way

    Like

  21. jpettys June 28, 2021 / 10:26 am

    Been a long time since you posted this, but it really helped me out today. 🙂

    Like

    • belle June 28, 2021 / 10:31 am

      That’s awesome, so happy to hear 🙂 thank you for sharing 🙂

      Like

Leave a comment