diff --git a/source/DSCResources/DSC_SqlRS/DSC_SqlRS.psm1 b/source/DSCResources/DSC_SqlRS/DSC_SqlRS.psm1 index 48d8007a4..c421d0b4a 100644 --- a/source/DSCResources/DSC_SqlRS/DSC_SqlRS.psm1 +++ b/source/DSCResources/DSC_SqlRS/DSC_SqlRS.psm1 @@ -254,10 +254,12 @@ function Get-TargetResource Report Manager/Report Web App virtual directory name. Optional. .PARAMETER ReportServerReservedUrl - Report Server URL reservations. Optional. + Report Server URL reservations. Optional. If not specified, + 'http://+:80' URL reservation will be used. .PARAMETER ReportsReservedUrl - Report Manager/Report Web App URL reservations. + Report Manager/Report Web App URL reservations. Optional. + If not specified, 'http://+:80' URL reservation will be used. .PARAMETER HttpsCertificateThumbprint The thumbprint of the certificate used to secure SSL communication. @@ -384,11 +386,11 @@ function Set-TargetResource [Parameter()] [System.String[]] - $ReportServerReservedUrl, + $ReportServerReservedUrl = @('http://+:80'), [Parameter()] [System.String[]] - $ReportsReservedUrl, + $ReportsReservedUrl = @('http://+:80'), [Parameter()] [System.String] @@ -848,103 +850,97 @@ function Set-TargetResource #endregion Virtual Directories #region Reserved URLs - if ( $PSBoundParameters.ContainsKey('EncryptionKeyBackupPath') ) - { - $compareParameters = @{ - ReferenceObject = $currentConfig.ReportServerReservedUrl - DifferenceObject = $ReportServerReservedUrl - } + $compareParameters = @{ + ReferenceObject = $currentConfig.ReportServerReservedUrl + DifferenceObject = $ReportServerReservedUrl + } - if ( ($null -ne $ReportServerReservedUrl) -and ($null -ne (Compare-Object @compareParameters)) ) - { - $restartReportingService = $true + if ( ($null -ne $ReportServerReservedUrl) -and ($null -ne (Compare-Object @compareParameters)) ) + { + $restartReportingService = $true - $currentConfig.ReportServerReservedUrl | ForEach-Object -Process { - $invokeRsCimMethodParameters = @{ - CimInstance = $reportingServicesData.Configuration - MethodName = 'RemoveURL' - Arguments = @{ - Application = 'ReportServerWebService' - UrlString = $_ - Lcid = $language - } + $currentConfig.ReportServerReservedUrl | ForEach-Object -Process { + $invokeRsCimMethodParameters = @{ + CimInstance = $reportingServicesData.Configuration + MethodName = 'RemoveURL' + Arguments = @{ + Application = 'ReportServerWebService' + UrlString = $_ + Lcid = $language } - - Invoke-RsCimMethod @invokeRsCimMethodParameters } - $ReportServerReservedUrl | ForEach-Object -Process { - Write-Verbose -Message "Adding report server URL reservation on $DatabaseServerName\$DatabaseInstanceName`: $_." - $invokeRsCimMethodParameters = @{ - CimInstance = $reportingServicesData.Configuration - MethodName = 'ReserveUrl' - Arguments = @{ - Application = 'ReportServerWebService' - UrlString = $_ - Lcid = $language - } - } + Invoke-RsCimMethod @invokeRsCimMethodParameters + } - Invoke-RsCimMethod @invokeRsCimMethodParameters + $ReportServerReservedUrl | ForEach-Object -Process { + Write-Verbose -Message "Adding report server URL reservation on $DatabaseServerName\$DatabaseInstanceName`: $_." + $invokeRsCimMethodParameters = @{ + CimInstance = $reportingServicesData.Configuration + MethodName = 'ReserveUrl' + Arguments = @{ + Application = 'ReportServerWebService' + UrlString = $_ + Lcid = $language + } } - # Get the current configuration - $currentConfig = Get-TargetResource @getTargetResourceParameters - Write-Verbose -Message ( $script:localizedData.ReportingServicesIsInitialized -f $DatabaseServerName, $DatabaseInstanceName, $currentConfig.IsInitialized ) -Verbose + Invoke-RsCimMethod @invokeRsCimMethodParameters } + + # Get the current configuration + $currentConfig = Get-TargetResource @getTargetResourceParameters + Write-Verbose -Message ( $script:localizedData.ReportingServicesIsInitialized -f $DatabaseServerName, $DatabaseInstanceName, $currentConfig.IsInitialized ) -Verbose } - if ( $PSBoundParameters.ContainsKey('ReportsReservedUrl') ) - { - $compareParameters = @{ - ReferenceObject = $currentConfig.ReportsReservedUrl - DifferenceObject = $ReportsReservedUrl - } + $compareParameters = @{ + ReferenceObject = $currentConfig.ReportsReservedUrl + DifferenceObject = $ReportsReservedUrl + } - if ( ($null -ne $ReportsReservedUrl) -and ($null -ne (Compare-Object @compareParameters)) ) - { - $restartReportingService = $true + if ( ($null -ne $ReportsReservedUrl) -and ($null -ne (Compare-Object @compareParameters)) ) + { + $restartReportingService = $true - $currentConfig.ReportsReservedUrl | ForEach-Object -Process { - $invokeRsCimMethodParameters = @{ - CimInstance = $reportingServicesData.Configuration - MethodName = 'RemoveURL' - Arguments = @{ - Application = $reportingServicesData.ReportsApplicationName - UrlString = $_ - Lcid = $language - } + $currentConfig.ReportsReservedUrl | ForEach-Object -Process { + $invokeRsCimMethodParameters = @{ + CimInstance = $reportingServicesData.Configuration + MethodName = 'RemoveURL' + Arguments = @{ + Application = $reportingServicesData.ReportsApplicationName + UrlString = $_ + Lcid = $language } - - Invoke-RsCimMethod @invokeRsCimMethodParameters } - $ReportsReservedUrl | ForEach-Object -Process { - Write-Verbose -Message ( - $script:localizedData.AddReportsUrlReservation -f @( - $DatabaseServerName - $DatabaseInstanceName - $_ - ) + Invoke-RsCimMethod @invokeRsCimMethodParameters + } + + $ReportsReservedUrl | ForEach-Object -Process { + Write-Verbose -Message ( + $script:localizedData.AddReportsUrlReservation -f @( + $DatabaseServerName + $DatabaseInstanceName + $_ ) + ) - $invokeRsCimMethodParameters = @{ - CimInstance = $reportingServicesData.Configuration - MethodName = 'ReserveUrl' - Arguments = @{ - Application = $reportingServicesData.ReportsApplicationName - UrlString = $_ - Lcid = $language - } + $invokeRsCimMethodParameters = @{ + CimInstance = $reportingServicesData.Configuration + MethodName = 'ReserveUrl' + Arguments = @{ + Application = $reportingServicesData.ReportsApplicationName + UrlString = $_ + Lcid = $language } - - Invoke-RsCimMethod @invokeRsCimMethodParameters } - # Get the current configuration - $currentConfig = Get-TargetResource @getTargetResourceParameters - Write-Verbose -Message ( $script:localizedData.ReportingServicesIsInitialized -f $DatabaseServerName, $DatabaseInstanceName, $currentConfig.IsInitialized ) -Verbose + Invoke-RsCimMethod @invokeRsCimMethodParameters } + + # Get the current configuration + $currentConfig = Get-TargetResource @getTargetResourceParameters + Write-Verbose -Message ( $script:localizedData.ReportingServicesIsInitialized -f $DatabaseServerName, $DatabaseInstanceName, $currentConfig.IsInitialized ) -Verbose } #endregion Reserved URLs @@ -1254,10 +1250,12 @@ function Set-TargetResource Report Manager/Report Web App virtual directory name. Optional. .PARAMETER ReportServerReservedUrl - Report Server URL reservations. Optional. + Report Server URL reservations. Optional. If not specified, + 'http://+:80' URL reservation will be used. .PARAMETER ReportsReservedUrl Report Manager/Report Web App URL reservations. Optional. + If not specified, 'http://+:80' URL reservation will be used. .PARAMETER HttpsCertificateThumbprint The thumbprint of the certificate used to secure SSL communication. @@ -1348,11 +1346,11 @@ function Test-TargetResource [Parameter()] [System.String[]] - $ReportServerReservedUrl, + $ReportServerReservedUrl = @('http://+:80'), [Parameter()] [System.String[]] - $ReportsReservedUrl, + $ReportsReservedUrl = @('http://+:80'), [Parameter()] [System.String] @@ -1528,30 +1526,27 @@ function Test-TargetResource } } - if ( $PSBoundParameters.ContainsKey('ReportsReservedUrl') ) + if ( $null -eq $currentConfig.ReportsReservedUrl ) + { + Write-Verbose -Message ( + $script:localizedData.ReportsReservedUrlNotInDesiredState -f $DatabaseServerName, $DatabaseInstanceName, '', ( $ReportsReservedUrl -join ', ' ) + ) -Verbose + $result = $false + } + else { - if ( $null -eq $currentConfig.ReportsReservedUrl ) + $compareParameters = @{ + ReferenceObject = $currentConfig.ReportsReservedUrl + DifferenceObject = $ReportsReservedUrl + } + + if ( $null -ne ( Compare-Object @compareParameters ) ) { Write-Verbose -Message ( - $script:localizedData.ReportsReservedUrlNotInDesiredState -f $DatabaseServerName, $DatabaseInstanceName, '', ( $ReportsReservedUrl -join ', ' ) + $script:localizedData.ReportsReservedUrlNotInDesiredState -f $DatabaseServerName, $DatabaseInstanceName, ( $currentConfig.ReportsReservedUrl -join ', ' ), ( $ReportsReservedUrl -join ', ' ) ) -Verbose $result = $false } - else - { - $compareParameters = @{ - ReferenceObject = $currentConfig.ReportsReservedUrl - DifferenceObject = $ReportsReservedUrl - } - - if ( $null -ne ( Compare-Object @compareParameters ) ) - { - Write-Verbose -Message ( - $script:localizedData.ReportsReservedUrlNotInDesiredState -f $DatabaseServerName, $DatabaseInstanceName, ( $currentConfig.ReportsReservedUrl -join ', ' ), ( $ReportsReservedUrl -join ', ' ) - ) -Verbose - $result = $false - } - } } if ($PSBoundParameters.ContainsKey('UseSsl') -and $UseSsl -ne $currentConfig.UseSsl) diff --git a/source/DSCResources/DSC_SqlRS/DSC_SqlRS.schema.mof b/source/DSCResources/DSC_SqlRS/DSC_SqlRS.schema.mof index 265c7ad53..15b2518a0 100644 --- a/source/DSCResources/DSC_SqlRS/DSC_SqlRS.schema.mof +++ b/source/DSCResources/DSC_SqlRS/DSC_SqlRS.schema.mof @@ -9,8 +9,8 @@ class DSC_SqlRS : OMI_BaseResource [Write, EmbeddedInstance("MSFT_Credential"), Description("The service account that should be used when running the _Windows_ service.")] String ServiceAccount; [Write, Description("_Report Server Web Service_ virtual directory. Optional.")] String ReportServerVirtualDirectory; [Write, Description("_Report Manager_ or _Report Web App_ virtual directory name. Optional.")] String ReportsVirtualDirectory; - [Write, Description("_Report Server_ URL reservations. Optional.")] String ReportServerReservedUrl[]; - [Write, Description("_Report Manager_ or _Report Web App_ URL reservations. Optional.")] String ReportsReservedUrl[]; + [Write, Description("_Report Server_ URL reservations. Optional. If not specified, `'http://+:80'` URL reservation will be used.")] String ReportServerReservedUrl[]; + [Write, Description("_Report Manager_ or _Report Web App_ URL reservations. Optional. If not specified, `'http://+:80'` URL reservation will be used.")] String ReportsReservedUrl[]; [Write, Description("The thumbprint of the certificate used to secure SSL communication.")] String HttpsCertificateThumbprint; [Write, Description("The IP address to bind the certificate specified in the _CertificateThumbprint_ parameter to. Default is `0.0.0.0` which binds to all IP addresses.")] String HttpsIPAddress; [Write, Description("The port used for SSL communication. Default is `443`.")] SInt32 HttpsPort; diff --git a/tests/Unit/DSC_SqlRS.Tests.ps1 b/tests/Unit/DSC_SqlRS.Tests.ps1 index 2c4d45cc0..19fbf6248 100644 --- a/tests/Unit/DSC_SqlRS.Tests.ps1 +++ b/tests/Unit/DSC_SqlRS.Tests.ps1 @@ -881,15 +881,15 @@ Describe 'SqlRS\Set-TargetResource' -Tag 'Set' { Should -Invoke -CommandName Invoke-RsCimMethod -ParameterFilter { $MethodName -eq 'ReserveUrl' -and $Arguments.Application -eq $mockReportServerApplicationName - } -Exactly -Times 0 -Scope It + } -Exactly -Times 1 -Scope It Should -Invoke -CommandName Invoke-RsCimMethod -ParameterFilter { $MethodName -eq 'ReserveUrl' -and $Arguments.Application -eq $mockReportsApplicationName - } -Exactly -Times 0 -Scope It + } -Exactly -Times 1 -Scope It Should -Invoke -CommandName Get-CimInstance -ParameterFilter { $ClassName -eq 'Win32_OperatingSystem' - } -Exactly -Times 8 -Scope It + } -Exactly -Times 10 -Scope It Should -Invoke -CommandName Invoke-SqlCmd -Exactly -Times 2 -Scope It Should -Invoke -CommandName Restart-ReportingServicesService -Exactly -Times 2 -Scope It @@ -1211,7 +1211,7 @@ Describe 'SqlRS\Set-TargetResource' -Tag 'Set' { Should -Invoke -CommandName Invoke-RsCimMethod -ParameterFilter { $MethodName -eq 'RemoveURL' -and $Arguments.Application -eq $mockReportServerApplicationName - } -Exactly -Times 1 -Scope It + } -Exactly -Times 2 -Scope It Should -Invoke -CommandName Invoke-RsCimMethod -ParameterFilter { $MethodName -eq 'RemoveURL' -and $Arguments.Application -eq $mockReportsApplicationName @@ -1252,7 +1252,7 @@ Describe 'SqlRS\Set-TargetResource' -Tag 'Set' { Should -Invoke -CommandName Invoke-RsCimMethod -ParameterFilter { $MethodName -eq 'ReserveUrl' -and $Arguments.Application -eq $mockReportServerApplicationName - } -Exactly -Times 0 -Scope It + } -Exactly -Times 1 -Scope It Should -Invoke -CommandName Invoke-RsCimMethod -ParameterFilter { $MethodName -eq 'ReserveUrl' -and $Arguments.Application -eq $mockReportsApplicationName @@ -1349,13 +1349,13 @@ Describe 'SqlRS\Set-TargetResource' -Tag 'Set' { Should -Invoke -CommandName Invoke-RsCimMethod -ParameterFilter { $MethodName -eq 'ReserveUrl' -and $Arguments.Application -eq $mockReportServerApplicationName - } -Exactly -Times 0 -Scope It + } -Exactly -Times 1 -Scope It Should -Invoke -CommandName Invoke-RsCimMethod -ParameterFilter { $MethodName -eq 'ReserveUrl' -and $Arguments.Application -eq $mockReportsApplicationNameLegacy - } -Exactly -Times 0 -Scope It + } -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Get-CimInstance -Exactly -Times 8 -Scope It + Should -Invoke -CommandName Get-CimInstance -Exactly -Times 10 -Scope It Should -Invoke -CommandName Invoke-SqlCmd -Exactly -Times 2 -Scope It Should -Invoke -CommandName Restart-ReportingServicesService -Exactly -Times 2 -Scope It @@ -1433,13 +1433,13 @@ Describe 'SqlRS\Set-TargetResource' -Tag 'Set' { Should -Invoke -CommandName Invoke-RsCimMethod -ParameterFilter { $MethodName -eq 'ReserveUrl' -and $Arguments.Application -eq $mockReportServerApplicationName - } -Exactly -Times 0 -Scope It + } -Exactly -Times 1 -Scope It Should -Invoke -CommandName Invoke-RsCimMethod -ParameterFilter { $MethodName -eq 'ReserveUrl' -and $Arguments.Application -eq $mockReportsApplicationName - } -Exactly -Times 0 -Scope It + } -Exactly -Times 1 -Scope It - Should -Invoke -CommandName Get-CimInstance -Exactly -Times 8 -Scope It + Should -Invoke -CommandName Get-CimInstance -Exactly -Times 10 -Scope It Should -Invoke -CommandName Invoke-Sqlcmd -Exactly -Times 2 -Scope It Should -Invoke -CommandName Restart-ReportingServicesService -Exactly -Times 2 -Scope It } @@ -1503,7 +1503,7 @@ Describe 'SqlRS\Set-TargetResource' -Tag 'Set' { Should -Invoke -CommandName Invoke-RsCimMethod -ParameterFilter { $MethodName -eq 'RemoveURL' -and $Arguments.Application -eq $mockReportServerApplicationName - } -Exactly -Times 1 -Scope It + } -Exactly -Times 2 -Scope It Should -Invoke -CommandName Invoke-RsCimMethod -ParameterFilter { $MethodName -eq 'RemoveURL' -and $Arguments.Application -eq $mockReportsApplicationName @@ -1535,7 +1535,7 @@ Describe 'SqlRS\Set-TargetResource' -Tag 'Set' { Should -Invoke -CommandName Invoke-RsCimMethod -ParameterFilter { $MethodName -eq 'ReserveUrl' -and $Arguments.Application -eq $mockReportServerApplicationName - } -Exactly -Times 0 -Scope It + } -Exactly -Times 1 -Scope It Should -Invoke -CommandName Invoke-RsCimMethod -ParameterFilter { $MethodName -eq 'ReserveUrl' -and $Arguments.Application -eq $mockReportsApplicationName