From 3adff1c7e853174f457b0b6d21acfc78d2fc8ad2 Mon Sep 17 00:00:00 2001 From: Marko Bozikovic Date: Wed, 14 Jun 2017 11:51:49 +0100 Subject: [PATCH] [#569] CR comments addressed. --- .../MSFT_xSQLServerRSConfig.psm1 | 62 +++++++++++-------- 1 file changed, 37 insertions(+), 25 deletions(-) diff --git a/DSCResources/MSFT_xSQLServerRSConfig/MSFT_xSQLServerRSConfig.psm1 b/DSCResources/MSFT_xSQLServerRSConfig/MSFT_xSQLServerRSConfig.psm1 index 368fd22b63..0526ae3520 100644 --- a/DSCResources/MSFT_xSQLServerRSConfig/MSFT_xSQLServerRSConfig.psm1 +++ b/DSCResources/MSFT_xSQLServerRSConfig/MSFT_xSQLServerRSConfig.psm1 @@ -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. @@ -107,7 +105,11 @@ 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 @@ -115,22 +117,22 @@ function Set-TargetResource 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 { @@ -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) }