In this post I will show you how to download Report form Report Server. This post is part of PowerShell series. You need to connect to Reporting Services endpoint see post Connect to Reporting Services with PowerShell
We use Reporting Services web method GetReportDefinition returning array of bytes. It will be encapsulated to DownloadReport function see script bellow.
- $proxy – Web Service Proxy
- $source – Report Server Report path {/Home/MyReports}
-
$destination – destination file path {c:\dir}
#downloadreport function DownloadReport($proxy,$source,$destination){ $reportDefinition | Out-Null try{ $reportDefinition = $proxy.GetReportDefinition($source) } catch { Write-Host " Problem to Get Report Definition call " $Error[0] } try{ [System.IO.FileStream] $fs | Out-Null $fs = [System.IO.File]::OpenWrite($destination+"\"+$ReportItem.Name+".rdl") $fs.Write($reportDefinition,0,$reportDefinition.Length) $fs.Close() } catch { Write-Host " Problem With saving report definiton to file " $Error[0] } }
To support mass download of reports lets prepare another one function using previous function together with ListChildren webservice method.
function DownloadReports($proxy,$source,$destination){ [Byte[]] $reportDefinition | Out-Null [SSRS.ReportingService2005.CatalogItem] $ReportItem | Out-Null $testpath = Test-Path $destination if ( $testpath -eq $false ) { Write-Host "Wrong path" return 0 } try{ foreach ($ReportItem in $proxy.ListChildren($source,$false)) { If ($ReportItem.Type -eq [SSRS.ReportingService2005.ItemTypeEnum]::Report){ DownloadReport $proxy $ReportItem.Path $destination } } } catch { Write-Host " List children method problem " $Error[0] } return 1 }
See example bellow
$proxy = ConnectToWebService "C:\config.xml" DownloadReports $proxy "/MyReports" "C:\dir_for_reports"