Skip to content

Commit

Permalink
[#569] CR comments addressed.
Browse files Browse the repository at this point in the history
  • Loading branch information
bozho committed Jun 14, 2017
1 parent 7767acf commit 008c15d
Showing 1 changed file with 37 additions and 25 deletions.
62 changes: 37 additions & 25 deletions DSCResources/MSFT_xSQLServerRSConfig/MSFT_xSQLServerRSConfig.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ Import-Module -Name (Join-Path -Path (Split-Path (Split-Path $PSScriptRoot -Pare
-ChildPath 'xSQLServerHelper.psm1') `
-Force



<#
.SYNOPSIS
Gets the SQL Reporting Services initialization status.
Expand Down Expand Up @@ -107,30 +105,34 @@ function Set-TargetResource

if ( Get-ItemProperty -Path $instanceNamesRegistryKey -Name $InstanceName -ErrorAction SilentlyContinue )
{
# smart import of the SQL module
<#
Import-SQLPSModule cmdlet will import SQLPS (SQL 2012/14) or SqlServer module (SQL 2016),
and if importing SQLPS, change directory back to the original one, since SQLPS changes the
current directory to SQLSERVER:\ on import.
#>
Import-SQLPSModule

$instanceId = (Get-ItemProperty -Path $instanceNamesRegistryKey -Name $InstanceName).$InstanceName
$sqlVersion = [System.Int32]((Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\$instanceId\Setup" -Name 'Version').Version).Split('.')[0]

if ( $InstanceName -eq 'MSSQLSERVER' )
{
$RSServiceName = 'ReportServer'
$RSVirtualDirectory = 'ReportServer'
$RMVirtualDirectory = 'Reports'
$RSDatabase = 'ReportServer'
$reportingServicesServiceName = 'ReportServer'
$reportServerVirtualDirectoryName = 'ReportServer'
$reportsVirtualDirectoryName = 'Reports'
$reportingServicesDatabaseName = 'ReportServer'
}
else
{
$RSServiceName = "ReportServer`$$InstanceName"
$RSVirtualDirectory = "ReportServer_$InstanceName"
$RMVirtualDirectory = "Reports_$InstanceName"
$RSDatabase = "ReportServer`$$InstanceName"
$reportingServicesServiceName = "ReportServer`$$InstanceName"
$reportServerVirtualDirectoryName = "ReportServer_$InstanceName"
$reportsVirtualDirectoryName = "Reports_$InstanceName"
$reportingServicesDatabaseName = "ReportServer`$$InstanceName"
}

if ( $RSSQLInstanceName -eq 'MSSQLSERVER' )
{
$reportingServicesConnnection = "$RSSQLServer"
$reportingServicesConnnection = $RSSQLServer
}
else
{
Expand All @@ -140,30 +142,40 @@ function Set-TargetResource
$language = (Get-WMIObject -Class Win32_OperatingSystem -Namespace root/cimv2 -ErrorAction SilentlyContinue).OSLanguage
$reportingServicesConfiguration = Get-WmiObject -Class MSReportServer_ConfigurationSetting -Namespace "root\Microsoft\SQLServer\ReportServer\RS_$InstanceName\v$sqlVersion\Admin"

if ( $reportingServicesConfiguration.VirtualDirectoryReportServer -ne $RSVirtualDirectory )
if ( $reportingServicesConfiguration.VirtualDirectoryReportServer -ne $reportServerVirtualDirectoryName )
{
$null = $reportingServicesConfiguration.SetVirtualDirectory('ReportServerWebService',$RSVirtualDirectory,$language)
$null = $reportingServicesConfiguration.SetVirtualDirectory('ReportServerWebService',$reportServerVirtualDirectoryName,$language)
$null = $reportingServicesConfiguration.ReserveURL('ReportServerWebService','http://+:80',$language)
}

if ( $reportingServicesConfiguration.VirtualDirectoryReportManager -ne $RMVirtualDirectory )
if ( $reportingServicesConfiguration.VirtualDirectoryReportManager -ne $reportsVirtualDirectoryName )
{
# SSRS Web Portal application name changed in SQL Server 2016
# https://docs.microsoft.com/en-us/sql/reporting-services/breaking-changes-in-sql-server-reporting-services-in-sql-server-2016
$virtualDirectoryName = if ($sqlVersion -ge 13) { 'ReportServerWebApp' } else { 'ReportManager'}
$null = $reportingServicesConfiguration.SetVirtualDirectory($virtualDirectoryName,$RMVirtualDirectory,$language)
<#
SSRS Web Portal application name changed in SQL Server 2016
https://docs.microsoft.com/en-us/sql/reporting-services/breaking-changes-in-sql-server-reporting-services-in-sql-server-2016
#>
if ($sqlVersion -ge 13)
{
$virtualDirectoryName = 'ReportServerWebApp'
}
else
{
$virtualDirectoryName = 'ReportManager'
}

$null = $reportingServicesConfiguration.SetVirtualDirectory($virtualDirectoryName,$reportsVirtualDirectoryName,$language)
$null = $reportingServicesConfiguration.ReserveURL($virtualDirectoryName,'http://+:80',$language)
}

$RSCreateScript = $reportingServicesConfiguration.GenerateDatabaseCreationScript($RSDatabase,$language,$false)
$reportingServicesDatabaseScript = $reportingServicesConfiguration.GenerateDatabaseCreationScript($reportingServicesDatabaseName,$language,$false)

# Determine RS service account
$RSSvcAccountUsername = (Get-WmiObject -Class Win32_Service | Where-Object {$_.Name -eq $RSServiceName}).StartName
$RSRightsScript = $reportingServicesConfiguration.GenerateDatabaseRightsScript($RSSvcAccountUsername,$RSDatabase,$false,$true)
$reportingServicesServiceAccountUserName = (Get-WmiObject -Class Win32_Service | Where-Object {$_.Name -eq $reportingServicesServiceName}).StartName
$reportingServicesDatabaseRightsScript = $reportingServicesConfiguration.GenerateDatabaseRightsScript($reportingServicesServiceAccountUserName,$reportingServicesDatabaseName,$false,$true)

Invoke-Sqlcmd -ServerInstance $reportingServicesConnnection -Query $RSCreateScript.Script
Invoke-Sqlcmd -ServerInstance $reportingServicesConnnection -Query $RSRightsScript.Script
$null = $reportingServicesConfiguration.SetDatabaseConnection($reportingServicesConnnection,$RSDatabase,2,'','')
Invoke-Sqlcmd -ServerInstance $reportingServicesConnnection -Query $reportingServicesDatabaseScript.Script
Invoke-Sqlcmd -ServerInstance $reportingServicesConnnection -Query $reportingServicesDatabaseRightsScript.Script
$null = $reportingServicesConfiguration.SetDatabaseConnection($reportingServicesConnnection,$reportingServicesDatabaseName,2,'','')
$null = $reportingServicesConfiguration.InitializeReportServer($reportingServicesConfiguration.InstallationID)
}

Expand Down

0 comments on commit 008c15d

Please sign in to comment.