diff --git a/CHANGELOG.md b/CHANGELOG.md index 49e21f588..fb0e7a8d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ # Change log for xSQLServer ## Unreleased +- Changes to xSQLServerRSConfig + - BREAKING CHANGE: removed $SQLAdminCredential parameter. Use common parameter PsDscRunAsCredential (WMF 5.0+) to run the resource under different credentials. PsDscRunAsCredential Windows account must be a sysadmin on SQL Server (issue #568). ## 7.1.0.0 @@ -65,7 +67,6 @@ - When TcpDynamicPorts is set to '0' the Test-TargetResource function will no longer fail each time (issue #564). - Changes to xSQLServerRSConfig - Replaced sqlcmd.exe usages with Invoke-Sqlcmd calls (issue #567). - - $SQLAdminCredential is now optional. To use the credential, CredSSP authentication must be properly configured on the target node. - Changes to xSQLServerDatabasePermission - Fixed code style, updated README.md and removed *-SqlDatabasePermission functions from xSQLServerHelper.psm1. - Added the option 'GrantWithGrant' with gives the user grant rights, together with the ability to grant others the same right. diff --git a/DSCResources/MSFT_xSQLServerRSConfig/MSFT_xSQLServerRSConfig.psm1 b/DSCResources/MSFT_xSQLServerRSConfig/MSFT_xSQLServerRSConfig.psm1 index 5fb6a1fe0..905c55ecc 100644 --- a/DSCResources/MSFT_xSQLServerRSConfig/MSFT_xSQLServerRSConfig.psm1 +++ b/DSCResources/MSFT_xSQLServerRSConfig/MSFT_xSQLServerRSConfig.psm1 @@ -20,11 +20,7 @@ function Get-TargetResource [parameter(Mandatory = $true)] [System.String] - $RSSQLInstanceName, - - [parameter()] - [System.Management.Automation.PSCredential] - $SQLAdminCredential + $RSSQLInstanceName ) if(Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\RS" -Name $InstanceName -ErrorAction SilentlyContinue) @@ -32,21 +28,7 @@ function Get-TargetResource $InstanceKey = (Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\RS" -Name $InstanceName).$InstanceName $SQLVersion = ((Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\$InstanceKey\Setup" -Name "Version").Version).Split(".")[0] - $invokeParameters = @{ - ArgumentList = @($SQLVersion,$InstanceName) - } - if($SQLAdminCredential -ne $null) { - $invokeParameters.Add("ComputerName", "localhost") - $invokeParameters.Add("Credential", $SQLAdminCredential) - $invokeParameters.Add("Authentication", "CredSSP") - } - - $RSConfig = Invoke-Command @invokeParameters -ScriptBlock { - $SQLVersion = $args[0] - $InstanceName = $args[1] - $RSConfig = Get-WmiObject -Class MSReportServer_ConfigurationSetting -Namespace "root\Microsoft\SQLServer\ReportServer\RS_$InstanceName\v$SQLVersion\Admin" - $RSConfig - } + $RSConfig = Get-WmiObject -Class MSReportServer_ConfigurationSetting -Namespace "root\Microsoft\SQLServer\ReportServer\RS_$InstanceName\v$SQLVersion\Admin" if($RSConfig.DatabaseServerName.Contains("\")) { $RSSQLServer = $RSConfig.DatabaseServerName.Split("\")[0] @@ -90,82 +72,60 @@ function Set-TargetResource [parameter(Mandatory = $true)] [System.String] - $RSSQLInstanceName, - - [parameter()] - [System.Management.Automation.PSCredential] - $SQLAdminCredential + $RSSQLInstanceName ) if(Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\RS" -Name $InstanceName -ErrorAction SilentlyContinue) { + # smart import of the SQL module + Import-SQLPSModule - $invokeParameters = @{ - ArgumentList = @("$currentPath\..\..\xSQLServerHelper.psm1", $InstanceName,$RSSQLServer,$RSSQLInstanceName) + $InstanceKey = (Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\RS" -Name $InstanceName).$InstanceName + $SQLVersion = ((Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\$InstanceKey\Setup" -Name "Version").Version).Split(".")[0] + if($InstanceName -eq "MSSQLSERVER") + { + $RSServiceName = "ReportServer" + $RSVirtualDirectory = "ReportServer" + $RMVirtualDirectory = "Reports" + $RSDatabase = "ReportServer" + } + else + { + $RSServiceName = "ReportServer`$$InstanceName" + $RSVirtualDirectory = "ReportServer_$InstanceName" + $RMVirtualDirectory = "Reports_$InstanceName" + $RSDatabase = "ReportServer`$$InstanceName" + } + if($RSSQLInstanceName -eq "MSSQLSERVER") + { + $RSConnection = "$RSSQLServer" } - if($SQLAdminCredential -ne $null) { - $invokeParameters.Add("ComputerName", "localhost") - $invokeParameters.Add("Credential", $SQLAdminCredential) - $invokeParameters.Add("Authentication", "CredSSP") + else + { + $RSConnection = "$RSSQLServer\$RSSQLInstanceName" } + $Language = (Get-WMIObject -Class Win32_OperatingSystem -Namespace root/cimv2 -ErrorAction SilentlyContinue).OSLanguage + $RSConfig = Get-WmiObject -Class MSReportServer_ConfigurationSetting -Namespace "root\Microsoft\SQLServer\ReportServer\RS_$InstanceName\v$SQLVersion\Admin" + if($RSConfig.VirtualDirectoryReportServer -ne $RSVirtualDirectory) + { + $null = $RSConfig.SetVirtualDirectory("ReportServerWebService",$RSVirtualDirectory,$Language) + $null = $RSConfig.ReserveURL("ReportServerWebService","http://+:80",$Language) + } + if($RSConfig.VirtualDirectoryReportManager -ne $RMVirtualDirectory) + { + $null = $RSConfig.SetVirtualDirectory("ReportManager",$RMVirtualDirectory,$Language) + $null = $RSConfig.ReserveURL("ReportManager","http://+:80",$Language) + } + $RSCreateScript = $RSConfig.GenerateDatabaseCreationScript($RSDatabase,$Language,$false) - Invoke-Command @invokeParameters -ScriptBlock { - # this is a separate PS session, need to load Common Code again - Import-Module $args[0] -Verbose -ErrorAction Stop - # smart import of the SQL module - Import-SQLPSModule - - $InstanceName = $args[1] - $RSSQLServer = $args[2] - $RSSQLInstanceName = $args[3] - $InstanceKey = (Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\RS" -Name $InstanceName).$InstanceName - $SQLVersion = ((Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\$InstanceKey\Setup" -Name "Version").Version).Split(".")[0] - if($InstanceName -eq "MSSQLSERVER") - { - $RSServiceName = "ReportServer" - $RSVirtualDirectory = "ReportServer" - $RMVirtualDirectory = "Reports" - $RSDatabase = "ReportServer" - } - else - { - $RSServiceName = "ReportServer`$$InstanceName" - $RSVirtualDirectory = "ReportServer_$InstanceName" - $RMVirtualDirectory = "Reports_$InstanceName" - $RSDatabase = "ReportServer`$$InstanceName" - } - if($RSSQLInstanceName -eq "MSSQLSERVER") - { - $RSConnection = "$RSSQLServer" - } - else - { - $RSConnection = "$RSSQLServer\$RSSQLInstanceName" - } - $Language = (Get-WMIObject -Class Win32_OperatingSystem -Namespace root/cimv2 -ErrorAction SilentlyContinue).OSLanguage - $RSConfig = Get-WmiObject -Class MSReportServer_ConfigurationSetting -Namespace "root\Microsoft\SQLServer\ReportServer\RS_$InstanceName\v$SQLVersion\Admin" - if($RSConfig.VirtualDirectoryReportServer -ne $RSVirtualDirectory) - { - $null = $RSConfig.SetVirtualDirectory("ReportServerWebService",$RSVirtualDirectory,$Language) - $null = $RSConfig.ReserveURL("ReportServerWebService","http://+:80",$Language) - } - if($RSConfig.VirtualDirectoryReportManager -ne $RMVirtualDirectory) - { - $null = $RSConfig.SetVirtualDirectory("ReportManager",$RMVirtualDirectory,$Language) - $null = $RSConfig.ReserveURL("ReportManager","http://+:80",$Language) - } - $RSCreateScript = $RSConfig.GenerateDatabaseCreationScript($RSDatabase,$Language,$false) - - # Determine RS service account - $RSSvcAccountUsername = (Get-WmiObject -Class Win32_Service | Where-Object {$_.Name -eq $RSServiceName}).StartName - $RSRightsScript = $RSConfig.GenerateDatabaseRightsScript($RSSvcAccountUsername,$RSDatabase,$false,$true) - - Invoke-Sqlcmd -ServerInstance $RSConnection -Query $RSCreateScript.Script - Invoke-Sqlcmd -ServerInstance $RSConnection -Query $RSRightsScript.Script - $RSConfig.SetDatabaseConnection($RSConnection,$RSDatabase,2,"","") - $RSConfig.InitializeReportServer($RSConfig.InstallationID) + # Determine RS service account + $RSSvcAccountUsername = (Get-WmiObject -Class Win32_Service | Where-Object {$_.Name -eq $RSServiceName}).StartName + $RSRightsScript = $RSConfig.GenerateDatabaseRightsScript($RSSvcAccountUsername,$RSDatabase,$false,$true) - } + Invoke-Sqlcmd -ServerInstance $RSConnection -Query $RSCreateScript.Script + Invoke-Sqlcmd -ServerInstance $RSConnection -Query $RSRightsScript.Script + $RSConfig.SetDatabaseConnection($RSConnection,$RSDatabase,2,"","") + $RSConfig.InitializeReportServer($RSConfig.InstallationID) } if(!(Test-TargetResource @PSBoundParameters)) @@ -191,11 +151,7 @@ function Test-TargetResource [parameter(Mandatory = $true)] [System.String] - $RSSQLInstanceName, - - [parameter()] - [System.Management.Automation.PSCredential] - $SQLAdminCredential + $RSSQLInstanceName ) $result = (Get-TargetResource @PSBoundParameters).IsInitialized diff --git a/DSCResources/MSFT_xSQLServerRSConfig/MSFT_xSQLServerRSConfig.schema.mof b/DSCResources/MSFT_xSQLServerRSConfig/MSFT_xSQLServerRSConfig.schema.mof index 7796e9246..06674454c 100644 --- a/DSCResources/MSFT_xSQLServerRSConfig/MSFT_xSQLServerRSConfig.schema.mof +++ b/DSCResources/MSFT_xSQLServerRSConfig/MSFT_xSQLServerRSConfig.schema.mof @@ -4,6 +4,5 @@ class MSFT_xSQLServerRSConfig : OMI_BaseResource [Key, Description("Name of the SQL Server Reporting Services instance to be configured.")] String InstanceName; [Required, Description("Name of the SQL Server to host the Reporting Service database.")] String RSSQLServer; [Required, Description("Name of the SQL Server instance to host the Reporting Service database.")] String RSSQLInstanceName; - [Write, EmbeddedInstance("MSFT_Credential"), Description("Credential to be used to perform the configuration. Optional.")] String SQLAdminCredential; [Read, Description("Is the Reporting Services instance initialized.")] Boolean IsInitialized; }; diff --git a/README.md b/README.md index 48c180454..97d56fc94 100644 --- a/README.md +++ b/README.md @@ -879,7 +879,6 @@ No description. * **[String] InstanceName** _(Key)_: Name of the SQL Server Reporting Services instance to be configured. * **[String] RSSQLServer** _(Required)_: Name of the SQL Server to host the Reporting Service database. * **[String] RSSQLInstanceName** _(Required)_: Name of the SQL Server instance to host the Reporting Service database. -* **[PSCredential] SQLAdminCredential** _(Required)_: Credential to be used to perform the configuration. #### Read-Only Properties from Get-TargetResource