diff --git a/CHANGELOG.md b/CHANGELOG.md index 220ed70c78..c07f1e7eeb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -59,9 +59,10 @@ - Refactored some of the code, cleaned up the rest and fixed PSSA rules warnings (issue #261). - If parameter TcpDynamicPort is set to '0' at the same time as TcpPort is set the resource will now throw an error (issue #535). - Added examples (issue #536). - - When TcpDynamicPorts is set to '0' the Test-TargetResource function will no longer fail each time (issue #564). -- Changes to xSQLServerRSConfig + - 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. ## 7.0.0.0 diff --git a/DSCResources/MSFT_xSQLServerRSConfig/MSFT_xSQLServerRSConfig.psm1 b/DSCResources/MSFT_xSQLServerRSConfig/MSFT_xSQLServerRSConfig.psm1 index f619d2b3fd..a9c1170109 100644 --- a/DSCResources/MSFT_xSQLServerRSConfig/MSFT_xSQLServerRSConfig.psm1 +++ b/DSCResources/MSFT_xSQLServerRSConfig/MSFT_xSQLServerRSConfig.psm1 @@ -22,7 +22,7 @@ function Get-TargetResource [System.String] $RSSQLInstanceName, - [parameter(Mandatory = $true)] + [parameter()] [System.Management.Automation.PSCredential] $SQLAdminCredential ) @@ -31,12 +31,22 @@ 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] - $RSConfig = Invoke-Command -ComputerName . -Credential $SQLAdminCredential -ScriptBlock { + + $invokeParameters = @{ + ComputerName = "localhost" + ArgumentList = @($SQLVersion,$InstanceName) + } + if($SQLAdminCredential -ne $null) { + $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 - } -ArgumentList @($SQLVersion,$InstanceName) + } if($RSConfig.DatabaseServerName.Contains("\")) { $RSSQLServer = $RSConfig.DatabaseServerName.Split("\")[0] @@ -82,14 +92,24 @@ function Set-TargetResource [System.String] $RSSQLInstanceName, - [parameter(Mandatory = $true)] + [parameter()] [System.Management.Automation.PSCredential] $SQLAdminCredential ) if(Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\RS" -Name $InstanceName -ErrorAction SilentlyContinue) { - Invoke-Command -ComputerName . -Credential $SQLAdminCredential -ScriptBlock { + + $invokeParameters = @{ + ComputerName = "localhost" + ArgumentList = @($InstanceName,$RSSQLServer,$RSSQLInstanceName) + } + if($SQLAdminCredential -ne $null) { + $invokeParameters.Add("Credential", $SQLAdminCredential) + $invokeParameters.Add("Authentication", "CredSSP") + } + + Invoke-Command @invokeParameters -ScriptBlock { # this is a separate PS session, need to load Common Code again Import-Module $using:currentPath\..\..\xSQLServerHelper.psm1 -Verbose -ErrorAction Stop # smart import of the SQL module @@ -145,7 +165,7 @@ function Set-TargetResource $RSConfig.SetDatabaseConnection($RSConnection,$RSDatabase,2,"","") $RSConfig.InitializeReportServer($RSConfig.InstallationID) - } -ArgumentList @($InstanceName,$RSSQLServer,$RSSQLInstanceName) + } } if(!(Test-TargetResource @PSBoundParameters)) @@ -173,7 +193,7 @@ function Test-TargetResource [System.String] $RSSQLInstanceName, - [parameter(Mandatory = $true)] + [parameter()] [System.Management.Automation.PSCredential] $SQLAdminCredential ) diff --git a/DSCResources/MSFT_xSQLServerRSConfig/MSFT_xSQLServerRSConfig.schema.mof b/DSCResources/MSFT_xSQLServerRSConfig/MSFT_xSQLServerRSConfig.schema.mof index 5891a288eb..4383dffe3c 100644 --- a/DSCResources/MSFT_xSQLServerRSConfig/MSFT_xSQLServerRSConfig.schema.mof +++ b/DSCResources/MSFT_xSQLServerRSConfig/MSFT_xSQLServerRSConfig.schema.mof @@ -4,6 +4,6 @@ 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; - [Required, EmbeddedInstance("MSFT_Credential"), Description("Credential to be used to perform the configuration.")] String SQLAdminCredential; + [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; };