ps/Modules/Alkami.DevOps.SqlReports/Public/New-SSRSReportsFolder.ps1
2023-05-30 22:51:22 -07:00

99 lines
3.3 KiB
PowerShell

function New-SSRSReportsFolder {
<#
.SYNOPSIS
Creates a New Top Level Folder in SSRS
.DESCRIPTION
Creates a folder with the specified name in the root directory of the specified SSRS server. If no parameters are provided, and
the function is being run on a Web server, the function attempts to read the configured ReportServer and ReportServerPath settings
from the machine.config
.PARAMETER folderName
[string] The name of the folder to create
.PARAMETER reportServerEndpoint
[string] The URL to the SSRS Report Server
.INPUTS
None
.OUTPUTS
None
.EXAMPLE
C:\Users\dsage> New-SSRSReportsFolder
[New-ReportServerFolder] : Created new folder /Firehost Production 999
.EXAMPLE
PS C:\Users\dsage> New-SSRSReportsFolder -FolderName "Firehost Production 999" -ReportServerUrl "http://ALKA02VMR001/ReportServer"
[New-ReportServerFolder] : Created new folder /Firehost Production 999
#>
[CmdletBinding()]
Param(
[Parameter(Position=0,Mandatory=$false)]
[Alias("Name")]
[string]$folderName,
[Parameter(Position=1,Mandatory=$false)]
[Alias("ReportServerUrl")]
[string]$reportServerEndpoint
)
$logLead = (Get-LogLeadName);
try
{
if (!(Test-IsWebServer) -and [String]::IsNullOrEmpty($reportServerEndpoint))
{
Write-Warning "$logLead : This function can only be automatically executed on a web tier server. To run, call the function with the appropriate parameters."
return
}
[xml]$config = Get-ReportServerConfiguration -WarningAction SilentlyContinue
if ($null -ne $config)
{
$reportServerEndpointNode = $config.appSettings.SelectSingleNode("//add[@key=""ReportServer""]/@value")
$reportFolderNode = $config.appSettings.SelectSingleNode("//add[@key=""ReportServerPath""]/@value")
}
if ((($null -eq $reportServerEndpointNode) -or ([String]::IsNullOrEmpty($reportServerEndpointNode.Value))) -and [String]::IsNullOrEmpty($reportServerEndpoint))
{
Write-Warning "$logLead : Could not read the value for the ""ReportServer"" appSetting from the machine.config and no report server URL was provided as a parameter. Execution cannot continue."
return;
}
if ((($null -eq $reportFolderNode) -or ([String]::IsNullOrEmpty($reportFolderNode.Value))) -and [String]::IsNullOrEmpty($folderName))
{
Write-Warning "$logLead : Could not read the value for the ""ReportServerPath"" appSetting from the machine.config and no folder name was provided as a parameter. Execution cannot continue."
return;
}
$folderToUse = IsNull $folderName $reportFolderNode.Value.TrimStart("/")
Write-Verbose ("$logLead : Using Report Folder $folderToUse")
$proxyUrlToUse = IsNull $reportServerEndpoint $reportServerEndpointNode.Value
Write-Verbose ("$logLead : Using Proxy Endpoint $proxyUrlToUse")
$proxy = New-SSRSProxy $proxyUrlToUse
New-ReportServerFolder $proxy $folderToUse
}
finally
{
if ($DisposeSessions)
{
if ($null -ne $SSRSProxy)
{
$SSRSProxy.Dispose()
}
if ($null -ne $SSRSExecutionProxy)
{
$SSRSExecutionProxy.Dispose()
}
}
}
}