75 lines
2.9 KiB
PowerShell
75 lines
2.9 KiB
PowerShell
function Publish-SqlReports {
|
|
<#
|
|
.SYNOPSIS
|
|
Publishes All Sql Reports in a Folder
|
|
|
|
.PARAMETER folder
|
|
|
|
Alias: ReportFolder
|
|
The path which contains the RDL files
|
|
.PARAMETER avoidDoubleHop
|
|
|
|
Alias: ApplyDoubleHopFix
|
|
Embeds the report username and password in the individual RDL files, necessary when SSRS does not run on the SQL Server
|
|
#>
|
|
|
|
[CmdletBinding()]
|
|
Param(
|
|
[Parameter(Position = 1, Mandatory = $true)]
|
|
[Alias("ReportFolder")]
|
|
[ValidateScript( {if (Test-Path $_ -PathType 'Container') {
|
|
$true
|
|
} else {
|
|
throw ("Unable to locate the folder {0}" -f $_)
|
|
}})]
|
|
[string]$folder,
|
|
|
|
[Parameter(Mandatory = $false)]
|
|
[Alias("ApplyDoubleHopFix")]
|
|
[switch]$avoidDoubleHop
|
|
)
|
|
|
|
$logLead = (Get-LogLeadName);
|
|
|
|
[System.Reflection.Assembly]::LoadWithPartialName("System.IO") | Out-Null
|
|
[System.Reflection.Assembly]::LoadWithPartialName("System.Data") | Out-Null
|
|
|
|
try {
|
|
if (Test-IsWebServer) {
|
|
|
|
$reportServerEndpoint = Get-AppSetting "ReportServer"
|
|
$reportFolder = Get-AppSetting "ReportServerPath"
|
|
|
|
if (($null -eq $reportFolder) -or ([String]::IsNullOrEmpty($reportFolder))) {
|
|
Write-Warning "$logLead : Could not read the value for the ""ReportServerPath"" appSetting from the machine.config.`n`nAutomatic execution cannot continue, but you may still run the script manually by passing the parameters to Publish-SSRSReportsDirectory"
|
|
return;
|
|
}
|
|
if (($null -eq $reportServerEndpoint) -or ([String]::IsNullOrEmpty($reportServerEndpoint))) {
|
|
Write-Warning "$logLead : Could not read the value for the ""ReportServer"" appSetting from the machine.config.`n`nAutomatic execution cannot continue, but you may still run the script manually by passing the parameters to Publish-SSRSReportsDirectory"
|
|
return;
|
|
}
|
|
|
|
Write-Host "`n$logLead : Automatically calling Publish-SSRSReportsDirectory with parameters:"
|
|
Write-Host ("$logLead : ReportDirectory : {0}" -f $folder)
|
|
Write-Host ("$logLead : WebServiceUrl : {0}" -f $reportServerEndpoint)
|
|
Write-Host ("$logLead : ReportFolder : {0}`n" -f $reportFolder)
|
|
|
|
Publish-SSRSReportsDirectory $folder $reportServerEndpoint $reportFolder -avoidDoubleHop:$AvoidDoubleHop.IsPresent
|
|
} else {
|
|
Write-Warning "$logLead : This script can only be automatically executed on a web tier server"
|
|
Write-Host "$logLead : You may still run the script manually by passing the parameters to Publish-SSRSReportsDirectory"
|
|
}
|
|
} finally {
|
|
if ($DisposeSessions) {
|
|
if ($null -ne $SSRSProxy) {
|
|
$SSRSProxy.Dispose()
|
|
}
|
|
|
|
if ($null -ne $SSRSExecutionProxy) {
|
|
$SSRSExecutionProxy.Dispose()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|