When I tweeted that I was working on a script to export reports from a Reporting Service point, I received a lot of response on that subject. In fact, I was only playing around to see if there was a quick way to migrate reports in a specific folder from one Reporting Service point to another. I had a bunch of reports that needed to be migrated, and after a quick search on the subject I came up with this excellent post. After a few test rounds I got it to work and was quite happy with the results. I decided to create two scripts, one that would deal with exporting the reports and one for importing them.
Download information
Both of the scripts have been made available on the TechNet Gallery.
Script documentation
As I’ve done for the past couple of scripts now, the scripts are built so that you can leverage PowerShell’s built in help functionality. You also have access to the common parameters like Verbose, Confirm and WhatIf. In addition to the common advanced functions the scripts has a ShowProgress switch that will show a progress bar with some extra information about the current operation and a Credential parameter. I’ve chosen to add this parameter because I realize that there could be scenarios where you’d run the PowerShell console under a different principal than you require to authenticate against the Reporting Service point, and in those scenarios the -UseDefaultCredentials for the New-WebServiceProxy would not be sufficient.
During the creation of these two scripts, I’ve been relying heavily on the SSRS online documentation, and I just have to say that it’s great, especially the ReportingService2010 class.
Usage
For the purpose of showing how I intended to use these two scripts together in a migration scenario, follow the instructions that I’ve outlined below. I’m going to export all the available reports in a folder called Power Management on a Reporting Service point installed on my server called CAS01. Since I don’t have another Reporting Service point server in my lab environment, I’ll simply import the reports back to the same server, but I will place them into a new folder called Custom Reports. Keep in mind that this scenario is not the one I intended when I created these scripts, even though it works just fine. In this example, I’ll be running my PowerShell console in user context that has the proper rights to access the Reporting Service point, so I’ll not be specifying any credentials. But if you require that, you can easily create a variable called e.g. $Creds that contains your credentials:
$Creds = Get-Credential
You’d then pass that variable as the argument for the Credential parameter.
1. Download the scripts from the TechNet Gallery and extract them to C:\Scripts.
2. Open an elevated PowerShell console (required if you wish to export the files somewhere that requires elevation) and browse to C:\Scripts.
3. Run the following command:
.\Export-CMReports.ps1 -ReportServer CAS01 -SiteCode CAS -FolderName "Power Management" -ExportPath "C:\Export" -ShowProgress -Verbose
Note! Remember to change the arguments entered in the command to reflect your environment.
As we can see the Export-CMReports.ps1 script will now start to download all of the reports available in the specified Report Service point folder. In addition, since we also specified the Verbose and ShowProgress parameters, we’re given a detailed information about the current operations that are ongoing. Once the script has successfully downloaded all reports, we can see the .rdl files if we browse to the path enter in the ExportPath parameter. In my scenario that path is C:\Export. Even though we only specified C:\Export in the parameter, and it clearly shows that we have a sub-folder structure of \ConfigMgr_CAS\Power Management, this is the default behavior I’ve built to avoid duplicate files and other issues that perhaps could occur.
4. Now that we have the reports exported to C:\Export\ConfigMgr_CAS\Power Management, let’s explore the Reporting Service point’s web service. We’re now going to import the .rdl files again to the same Reporting Service point (obviously this would be another server in a migration scenario) to see if there’s a folder called Custom Reports. Open a browser and go to https://<FQDN>/Reports, in my scenario https://CAS01.contoso.com/Reports. As we can see in the picture below,there’s no folder called Custom Reports. Great, we’ll take care of that later.
5. Run the following command:
.\Import-CMReports.ps1 -ReportServer CAS01 -SiteCode CAS -FolderName "Custom Reports" -SourcePath "C:\Export\ConfigMgr_CAS\Power Management" -Force -Verbose -ShowProgress
Note! Remember to change the arguments entered in the command to reflect your environment.
The import process will now begin. Since we didn’t have a folder called Custom Reports, but specified it for the FolderName parameter, you’d assume that the command would fail. But, we’ve also included the Force switch which will create the folder if it doesn’t already exist. In addition we’ll also be shown the current operation.
Once the script has successfully imported all of the reports in the specified path, lets browse the web service once more to see if the reports are present:
First off we can see that the Custom Reports folder has been created, and within that folder are all of the imported Power Management reports:
That’s it, the reports have now been successfully migrated.
Hi,
Try to execute Export Powershell command and received below error.
Unable to find type [ordered]: make sure that the assembly containing this type is loaded.
At C:\Export-CMReports.ps1:63 char:27
+ $ProxyArgs = [ordered] <<<< @{
+ CategoryInfo : InvalidOperation: (ordered:String) [], RuntimeException
+ FullyQualifiedErrorId : TypeNotFound
VERBOSE: Credentials was not provided, using default
The argument is null or empty. Supply an argument that is not null or empty and then try the command again.
At C:\Export-CMReports.ps1:133 char:14
+ Throw <<<< $_.Exception.Message
+ CategoryInfo : OperationStopped: (The argument is… command again.:String) [], RuntimeException
+ FullyQualifiedErrorId : The argument is null or empty. Supply an argument that is not null or empty and then try
the command again.
I used to execute the same command in my ITLAB and One of the production environment but this time I am facing the mentioned error. Please help.
Thank you.
Regards,
Sam
Hi Sam,
What PowerShell version are you running this script on? Write $host in a console to get the version.
Regards,
Nickolaj
Hi Nicholaj,
Powershell Version is 2.0. The server which I am using is running with Windows Server 2008 Standard Edition SP2.
Also in My ITLAB the SCCM server is running on WindowS Server 2012 Standard Edition with Powershell Version 4.0
Please let me know if you need more information.
Regards,
Sam
I used the import script to import some .rdl file from one report server to another server.
But, I received the error “The Data source ‘ ‘ cannot be found”.
how can we use this script to import to different server?
Hi Nickolaj
Thanks for the blog post. Saved me some time!
Cheers,
Al
When running import script, you will need to add the subfolder path that was created or you get this error:
WARNING: No .rdl files was found in the specified path
Don’t put the script in double quotes or you will get errors:
At line:1 char:46
+ “F:\src\MigrateReports\Export-CMReports.ps1” -ReportServer myservername -SiteCode …
+ ~~~~~~~~~~~~~
Unexpected token ‘-ReportServer’ in expression or statement.
At line:1 char:60
+ “F:\src\MigrateReports\Export-CMReports.ps1” -ReportServer myservername -SiteCode …
+ ~~~~~~~~~~~
Unexpected token ‘myservername’ in expression or statement.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : UnexpectedToken
Thanks you for your for this post.
It Works.
Hi Oded,
Wonderful that it works, glad to hear!
Regards,
Nickolaj
Hi, 1st off, great work on your scripts, I’ve used some and they’re very well made/useful.
2nd, I’ve tried to run your script against our report server, it showed me these two messages:
VERBOSE: Credentials was not provided, using default
VERBOSE: FolderName parameter was specified, matching results
But the export folder is empty. What is the sitecode that you’re providing? Our CAS site code? our is there one for the report server?
Thks in advance and don’t hesitate if you have any questions.
Steph
Hi Steph,).
Thank you very much for your kind words 🙂
The SiteCode parameter should be populated with the Site Code of the Site Server where the Reporting Service Point is located. In the case where you’re running an hierarchy with a CAS and the Reporting Service Point is installed on the CAS server, provide the Site Code of the CAS server. This is then used to construct the correct path in SSRS (default is ConfigMgr_
Regards,
Nickolaj