Deploy SSRS files automatically

This series of scripts will deploy an entire directory worth of RDL scripts, or roll them back (undeploy). See my other posting on CreateDirIfItDoesNotExist

Tools are the Install-SSRSDL.ps1, Uninstall-SSRSDL.ps1 scripts.
Install-SSRSDL.sp1

<#
.SYNOPSIS
Installs an RDL file to SQL Reporting Server using Web Service

.DESCRIPTION
Installs an RDL file to SQL Reporting Server using Web Service

.NOTES
File Name: Install-SSRSRDL.ps1
Author: Randy Aldrich Paulo
Prerequisite: SSRS 2008, Powershell 2.0

.PARAMETER reportName
Name of report wherein the rdl file will be saved as in Report Server.
If this is not specified, it will get the name from the file (rdl) exluding the file extension.

.PARAMETER force
If force is specified it will create the report folder if not existing
and overwrites the report if existing.

.EXAMPLE
Install-SSRSRDL -webServiceUrl "http://[ServerName]/ReportServer/ReportService2005.asmx?WSDL&quot; -rdlFile "C:\Report.rdl" -force

.EXAMPLE
Install-SSRSRDL "http://[ServerName]/ReportServer/ReportService2005.asmx?WSDL&quot; "C:\Report.rdl" -force

.EXAMPLE
Install-SSRSRDL "http://[ServerName]/ReportServer/ReportService2005.asmx?WSDL&quot; "C:\Report.rdl" -force -reportName "MyReport"

.EXAMPLE
Install-SSRSRDL "http://[ServerName]/ReportServer/ReportService2005.asmx?WSDL&quot; "C:\Report.rdl" -force -reportFolder "Reports" -reportName "MyReport"

#>
function Install-SSRSRDL
(
[Parameter(Position=0,Mandatory=$true)]
[Alias("url")]
[string]$webServiceUrl,

[ValidateScript({Test-Path $_})]
[Parameter(Position=1,Mandatory=$true)]
[Alias("rdl")]
[string]$rdlFile,

[Parameter(Position=2)]
[Alias("folder")]
[string]$reportFolder="",

[Parameter(Position=3)]
[Alias("name")]
[string]$reportName="",

[switch]$force
)
{
$ErrorActionPreference="Stop"

#Create Proxy
Write-Host "[Install-SSRSRDL()] Creating Proxy, connecting to : $webServiceUrl"
$ssrsProxy = New-WebServiceProxy -Uri $webServiceUrl -UseDefaultCredential
$reportPath = "/"
$errorsFound = 0

if($force)
{
#Check if folder is existing, create if not found
try
{
$ssrsProxy.CreateFolder($reportFolder, $reportPath, $null)
Write-Host "[Install-SSRSRDL()] Created new folder: $reportFolder"
}
catch [System.Web.Services.Protocols.SoapException]
{
if ($_.Exception.Detail.InnerText -match "[^rsItemAlreadyExists400]")
{
Write-Host "[Install-SSRSRDL()] Folder: $reportFolder already exists."
}
else
{
$msg = "[Install-SSRSRDL()] Error creating folder: $reportFolder. Msg: '{0}'" -f $_.Exception.Detail.InnerText
Write-Error $msg
$errorsFound = 1
}
}
}

#Set reportname if blank, default will be the filename without extension
if($reportName -eq "")
{
$reportName = [System.IO.Path]::GetFileNameWithoutExtension($rdlFile);
}
Write-Host "[Install-SSRSRDL()] Report name set to: $reportName"

try
{
#Get Report content in bytes
Write-Host "[Install-SSRSRDL()] Getting file content (byte) of : $rdlFile"
$byteArray = gc $rdlFile -encoding byte
$msg = "[Install-SSRSRDL()] Total length: {0}" -f $byteArray.Length
Write-Host $msg

$reportFolder = $reportPath + $reportFolder
Write-Host "[Install-SSRSRDL()] Uploading to: $reportFolder"

#Call Proxy to upload report
$warnings = $ssrsProxy.CreateReport($reportName,$reportFolder,$force,$byteArray,$null)
if ($warnings.Length -eq $null)
{
Write-Host "[Install-SSRSRDL()] Upload Success."
}
else
{
$warnings | % { Write-Warning "[Install-SSRSRDL()] Warning: $_" }
}
}
catch [System.IO.IOException]
{
$msg = "[Install-SSRSRDL()] Error while reading rdl file : '{0}', Message: '{1}'" -f $rdlFile, $_.Exception.Message
Write-Error msg
$errorsFound = 1
}
catch [System.Web.Services.Protocols.SoapException]
{
$msg = "[Install-SSRSRDL()] Error while uploading rdl file : '{0}', Message: '{1}'" -f $rdlFile, $_.Exception.Detail.InnerText
Write-Error $msg
$errorsFound = 1
}
return $errorsFound
}

Uninstall-SSRSRDL.ps1

<#
.SYNOPSIS
Uninstalls an RDL file from SQL Reporting Server using Web Service

.DESCRIPTION
Uninstalls an RDL file from SQL Reporting Server using Web Service

.NOTES
File Name: Uninstall-SSRSRDL.ps1
Author: Randy Aldrich Paulo
Prerequisite: SSRS 2008, Powershell 2.0

.EXAMPLE
Uninstall-SSRSRDL -webServiceUrl "http://[ServerName]/ReportServer/ReportService2005.asmx?WSDL&quot; -path "MyReport"

.EXAMPLE
Uninstall-SSRSRDL -webServiceUrl "http://[ServerName]/ReportServer/ReportService2005.asmx?WSDL&quot; -path "Reports/Report1"

#>
function Uninstall-SSRSRDL
(
[Parameter(Position=0,Mandatory=$true)]
[Alias("url")]
[string]$webServiceUrl,

[Parameter(Position=1,Mandatory=$true)]
[Alias("path")]
[string]$reportPath
)

{
#Create Proxy
Write-Host "[Uninstall-SSRSRDL()] Creating Proxy, connecting to : $webServiceUrl"
$ssrsProxy = New-WebServiceProxy -Uri $webServiceUrl -UseDefaultCredential

#Set Report Folder
if(!$reportPath.StartsWith("/")) { $reportPath = "/" + $reportPath }

try
{

Write-Host "[Uninstall-SSRSRDL()] Deleting: $reportPath"
#Call Proxy to upload report
$ssrsProxy.DeleteItem($reportPath)
Write-Host "[Uninstall-SSRSRDL()] Delete Success."
}
catch [System.Web.Services.Protocols.SoapException]
{
$msg = "[Uninstall-SSRSRDL()] Error while deleting report : '{0}', Message: '{1}'" -f $reportPath, $_.Exception.Detail.InnerText
Write-Error $msg
}

}

Here is a sample that drives the two. Note VERY IMPORTANT the url for reporting services itself (reaches the web service is anti-intuitive)
http://10.200.30.101/ReportServer_SQL20 ... .asmx?wsdl

the bcomp command referred to below is for a Beyond Compare 3 tool made by Scooter software (powerful $35.00 tool).

. .\Install-SSRSRDL.ps1
. .\Uninstall-SSRSRDL.ps1
. .\CreateDirIfItDoesNotExist.ps1
# This script does the heavy lifting of the deployment
# Red Gate will get the binaries to the first target, but if this is the COLO we need to run a
# Beyond Compare script to synch server 1 to server 2 for Live or Staging

$ElapsedStopWatch = [System.Diagnostics.Stopwatch]::StartNew()

# $RedGatePackageDirectoryPath is the On Deck Circle where the package is initial extracted.
# JUST FOR TESTING DON't DO THIS!
$RedGateEnvironmentName = "QA"
$ApplicationRollbackPath = "D:\Builds\IDD\PainEdu2\Solution Files\PainCASReport.Solution\Rollback"
$IsRollback = "false"
$ReportingServicesUrl = "http://10.200.30.100/ReportServer_SQL2008/ReportService2005.asmx?wsdl&quot; # yes I know.


"The environment PainCAS Reporting services is targetting " + $RedGateEnvironmentName | Write-Host

if ([string]::IsNullOrEmpty($RedGatePackageDirectoryPath))
{
$RedGatePackageDirectoryPath = "D:\Builds\IDD\PainEdu2\Solution Files\PainCASReport.Solution\Distribution\PainCASReport"
}

"The package binaries are in " + $RedGatePackageDirectoryPath | Write-Host



if ($IsRollback.ToLower() -eq "true")
{
"Rollback of PainCASReports is TRUE." | Write-Host
$path = [String]::Format("{0}/{1}", $ApplicationRollbackPath, "PainCASReport")
set-location $path
get-location
# need to restore the old ones.
Get-ChildItem $ApplicationRollbackPath -File *.rdl | `
Foreach-Object{

Install-SSRSRDL $ReportingServicesUrl $_.FullName -force -reportFolder "painCAS_AssessmentReport"
}
}
else
{

# Now the actual deployment...

"Deploying PainCASReport RDLs" | Write-Host
# these steps are crucial
set-location $RedGatePackageDirectoryPath
get-location
$foundErrors = 0
Get-ChildItem $RedGatePackageDirectoryPath -File *.rdl | `
Foreach-Object{

$errorFound = Install-SSRSRDL $ReportingServicesUrl $_.FullName -force -reportFolder "painCAS_AssessmentReport"
if ($errorFound -ne 0)
{
$foundErrors = $foundErrors + 1
}
}

if ($foundErrors -eq 0)
{
"Backing up the existing PainCASReport services" | Write-host
# Make certain that the path d:\ApplicationRollback\PainCASReport exists
$rollbackPath = [String]::Format("{0}/{1}", $ApplicationRollbackPath, "PainCASReport")
if (!(Test-Path ($rollbackPath)))
{
[IO.Directory]::CreateDirectory($rollbackPath)
"Created the " + $rollbackPath | Write-Host
}

"The full backup path for Reports is " + $rollbackPath | Write-Host

set-location $RedGatePackageDirectoryPath
get-location

# Now copy the entire web site to a backup folder the tick ` is an escape char for "
"About to run " + "& bcomp " + "@BackupPainCAS.bc" + " " + $RedGatePackageDirectoryPath + " " + $rollbackPath | Write-Host

& bcomp "@BackupPainCASReport.bc" $RedGatePackageDirectoryPath $rollbackPath
}
}
# Stop the timer
$elapsedTime = $ElapsedStopWatch.Elapsed.ToString()
$elapsedTime | Write-Host
Sign In or Register to comment.