Skip to content

Commit

Permalink
[dsccommunity#568] xSQLServerRSConfig: $SQLAdminCredential is now opt…
Browse files Browse the repository at this point in the history
…ional
  • Loading branch information
bozho committed Jun 5, 2017
1 parent f374f39 commit 44c9ff1
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 9 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,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).
- 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.
Expand Down
34 changes: 27 additions & 7 deletions DSCResources/MSFT_xSQLServerRSConfig/MSFT_xSQLServerRSConfig.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function Get-TargetResource
[System.String]
$RSSQLInstanceName,

[parameter(Mandatory = $true)]
[parameter()]
[System.Management.Automation.PSCredential]
$SQLAdminCredential
)
Expand All @@ -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]
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -145,7 +165,7 @@ function Set-TargetResource
$RSConfig.SetDatabaseConnection($RSConnection,$RSDatabase,2,"","")
$RSConfig.InitializeReportServer($RSConfig.InstallationID)

} -ArgumentList @($InstanceName,$RSSQLServer,$RSSQLInstanceName)
}
}

if(!(Test-TargetResource @PSBoundParameters))
Expand Down Expand Up @@ -173,7 +193,7 @@ function Test-TargetResource
[System.String]
$RSSQLInstanceName,

[parameter(Mandatory = $true)]
[parameter()]
[System.Management.Automation.PSCredential]
$SQLAdminCredential
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

0 comments on commit 44c9ff1

Please sign in to comment.