Skip to content

Commit

Permalink
[dsccommunity#568] Removed $SQLAdminCredential parameter.
Browse files Browse the repository at this point in the history
xSQLServer module aims to drop WMF 4.0 support. WMF 5.0 and later
supports a common parameter (PsDscRunAsCredential) for running DSC
resources under different credentials, which eliminates the need for
the $SQLAdminCredential parameter.
  • Loading branch information
bozho authored and johlju committed May 26, 2017
1 parent 01596a4 commit fe55875
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 94 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
- 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.
- 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.0.0.0

Expand Down
140 changes: 48 additions & 92 deletions DSCResources/MSFT_xSQLServerRSConfig/MSFT_xSQLServerRSConfig.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -20,33 +20,15 @@ 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)
{
$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]
Expand Down Expand Up @@ -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))
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

0 comments on commit fe55875

Please sign in to comment.