Skip to content

Commit e9268cc

Browse files
authored
Remove InstanceName from Restart-ReportingServicesService (#2339)
1 parent 1703817 commit e9268cc

File tree

3 files changed

+14
-127
lines changed

3 files changed

+14
-127
lines changed

CHANGELOG.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
236236
### Changed
237237

238238
- `Restart-ReportingServicesService`
239-
- Add the ServiceName parameter to restart service with the service name specified.
240-
- Introduce parameter sets to maintain backward compatibility with the current
241-
version.
239+
- BREAKING CHANGE: Removed the deprecated `InstanceName` parameter. All callers
240+
must now use the `ServiceName` parameter instead.
241+
- Added the `ServiceName` parameter to restart service with the service name specified.
242242
- BREAKING CHANGE: `Set-SqlDscDatabase` has been renamed to `Set-SqlDscDatabaseProperty`
243243
to better reflect its purpose of setting database properties. All existing references
244244
should be updated to use the new name.

source/Modules/SqlServerDsc.Common/SqlServerDsc.Common.psm1

Lines changed: 4 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,10 +1099,6 @@ function Restart-SqlClusterService
10991099
.SYNOPSIS
11001100
Restarts a Reporting Services instance and associated services
11011101
1102-
.PARAMETER InstanceName
1103-
Name of the instance to be restarted. Default is 'MSSQLSERVER'
1104-
(the default instance).
1105-
11061102
.PARAMETER ServiceName
11071103
Name of the service to be restarted.
11081104
@@ -1112,14 +1108,10 @@ function Restart-SqlClusterService
11121108
#>
11131109
function Restart-ReportingServicesService
11141110
{
1115-
[CmdletBinding(DefaultParameterSetName = 'InstanceName')]
1111+
[CmdletBinding()]
11161112
param
11171113
(
1118-
[Parameter(ParameterSetName = 'InstanceName')]
1119-
[System.String]
1120-
$InstanceName = 'MSSQLSERVER',
1121-
1122-
[Parameter(ParameterSetName = 'ServiceName', Mandatory = $true)]
1114+
[Parameter(Mandatory = $true)]
11231115
[System.String]
11241116
$ServiceName,
11251117

@@ -1128,37 +1120,8 @@ function Restart-ReportingServicesService
11281120
$WaitTime = 0
11291121
)
11301122

1131-
if ($InstanceName -eq 'SSRS')
1132-
{
1133-
# Check if we're dealing with SSRS 2017 or SQL2019
1134-
$ServiceName = 'SQLServerReportingServices'
1135-
1136-
Write-Verbose -Message ($script:localizedData.GetServiceInformation -f $ServiceName) -Verbose
1137-
$reportingServicesService = Get-Service -Name $ServiceName -ErrorAction SilentlyContinue
1138-
}
1139-
1140-
if ($PSCmdlet.ParameterSetName -eq 'ServiceName')
1141-
{
1142-
Write-Verbose -Message ($script:localizedData.GetServiceInformation -f $ServiceName) -Verbose
1143-
$reportingServicesService = Get-Service -Name $ServiceName
1144-
}
1145-
1146-
if ($null -eq $reportingServicesService)
1147-
{
1148-
$ServiceName = 'ReportServer'
1149-
1150-
<#
1151-
Pre-2017 SSRS support multiple instances, check if we're dealing
1152-
with a named instance.
1153-
#>
1154-
if (-not ($InstanceName -eq 'MSSQLSERVER'))
1155-
{
1156-
$ServiceName += '${0}' -f $InstanceName
1157-
}
1158-
1159-
Write-Verbose -Message ($script:localizedData.GetServiceInformation -f $ServiceName) -Verbose
1160-
$reportingServicesService = Get-Service -Name $ServiceName
1161-
}
1123+
Write-Verbose -Message ($script:localizedData.GetServiceInformation -f $ServiceName) -Verbose
1124+
$reportingServicesService = Get-Service -Name $ServiceName
11621125

11631126
<#
11641127
Get all dependent services that are running.

tests/Unit/SqlServerDsc.Common.Tests.ps1

Lines changed: 7 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -2816,7 +2816,7 @@ Describe 'SqlServerDsc.Common\Restart-ReportingServicesService' -Tag 'RestartRep
28162816
}
28172817
}
28182818

2819-
Context 'When restarting a Report Services default instance' {
2819+
Context 'When restarting a Report Services service name is supplied' {
28202820
BeforeAll {
28212821
$mockServiceName = 'ReportServer'
28222822
$mockDependedServiceName = 'DependentService'
@@ -2831,94 +2831,17 @@ Describe 'SqlServerDsc.Common\Restart-ReportingServicesService' -Tag 'RestartRep
28312831
}
28322832

28332833
It 'Should restart the service and dependent service' {
2834-
$null = Restart-ReportingServicesService -InstanceName 'MSSQLSERVER'
2835-
2836-
Should -Invoke -CommandName Get-Service -ParameterFilter {
2837-
$Name -eq $mockServiceName
2838-
} -Scope It -Exactly -Times 1
2839-
Should -Invoke -CommandName Stop-Service -Scope It -Exactly -Times 1
2840-
Should -Invoke -CommandName Start-Service -Scope It -Exactly -Times 2
2841-
}
2842-
}
2843-
2844-
Context 'When restarting a SQL Server 2017 (or newer) Report Services' {
2845-
BeforeAll {
2846-
$mockServiceName = 'SQLServerReportingServices'
2847-
$mockDependedServiceName = 'DependentService'
2848-
2849-
$mockDynamicServiceName = $mockServiceName
2850-
$mockDynamicDependedServiceName = $mockDependedServiceName
2851-
$mockDynamicServiceDisplayName = 'Reporting Services'
2852-
2853-
Mock -CommandName Stop-Service
2854-
Mock -CommandName Start-Service
2855-
Mock -CommandName Get-Service -MockWith $mockGetService
2856-
}
2857-
2858-
It 'Should restart the service and dependent service' {
2859-
$null = Restart-ReportingServicesService -InstanceName 'SSRS'
2860-
2861-
Should -Invoke -CommandName Get-Service -ParameterFilter {
2862-
$Name -eq $mockServiceName
2863-
} -Scope It -Exactly -Times 1
2864-
Should -Invoke -CommandName Stop-Service -Scope It -Exactly -Times 1
2865-
Should -Invoke -CommandName Start-Service -Scope It -Exactly -Times 2
2866-
}
2867-
}
2868-
2869-
Context 'When restarting a Report Services named instance' {
2870-
BeforeAll {
2871-
$mockServiceName = 'ReportServer$TEST'
2872-
$mockDependedServiceName = 'DependentService'
2873-
2874-
$mockDynamicServiceName = $mockServiceName
2875-
$mockDynamicDependedServiceName = $mockDependedServiceName
2876-
$mockDynamicServiceDisplayName = 'Reporting Services (TEST)'
2877-
2878-
Mock -CommandName Stop-Service
2879-
Mock -CommandName Start-Service
2880-
Mock -CommandName Get-Service -MockWith $mockGetService
2881-
}
2882-
2883-
It 'Should restart the service and dependent service' {
2884-
$null = Restart-ReportingServicesService -InstanceName 'TEST'
2885-
2886-
Should -Invoke -CommandName Get-Service -ParameterFilter {
2887-
$Name -eq $mockServiceName
2888-
} -Scope It -Exactly -Times 1
2889-
Should -Invoke -CommandName Stop-Service -Scope It -Exactly -Times 1
2890-
Should -Invoke -CommandName Start-Service -Scope It -Exactly -Times 2
2891-
}
2892-
}
2893-
2894-
Context 'When restarting a Report Services named instance using a wait timer' {
2895-
BeforeAll {
2896-
$mockServiceName = 'ReportServer$TEST'
2897-
$mockDependedServiceName = 'DependentService'
2898-
2899-
$mockDynamicServiceName = $mockServiceName
2900-
$mockDynamicDependedServiceName = $mockDependedServiceName
2901-
$mockDynamicServiceDisplayName = 'Reporting Services (TEST)'
2902-
2903-
Mock -CommandName Start-Sleep
2904-
Mock -CommandName Stop-Service
2905-
Mock -CommandName Start-Service
2906-
Mock -CommandName Get-Service -MockWith $mockGetService
2907-
}
2908-
2909-
It 'Should restart the service and dependent service' {
2910-
$null = Restart-ReportingServicesService -InstanceName 'TEST' -WaitTime 1
2834+
$null = Restart-ReportingServicesService -ServiceName 'ReportServer'
29112835

29122836
Should -Invoke -CommandName Get-Service -ParameterFilter {
29132837
$Name -eq $mockServiceName
29142838
} -Scope It -Exactly -Times 1
29152839
Should -Invoke -CommandName Stop-Service -Scope It -Exactly -Times 1
29162840
Should -Invoke -CommandName Start-Service -Scope It -Exactly -Times 2
2917-
Should -Invoke -CommandName Start-Sleep -Scope It -Exactly -Times 1
29182841
}
29192842
}
29202843

2921-
Context 'When restarting a Report Services service name is supplied' {
2844+
Context 'When restarting a Report Services service with wait timer' {
29222845
BeforeAll {
29232846
$mockServiceName = 'ReportServer'
29242847
$mockDependedServiceName = 'DependentService'
@@ -2927,21 +2850,22 @@ Describe 'SqlServerDsc.Common\Restart-ReportingServicesService' -Tag 'RestartRep
29272850
$mockDynamicDependedServiceName = $mockDependedServiceName
29282851
$mockDynamicServiceDisplayName = 'Reporting Services (MSSQLSERVER)'
29292852

2853+
Mock -CommandName Start-Sleep
29302854
Mock -CommandName Stop-Service
29312855
Mock -CommandName Start-Service
29322856
Mock -CommandName Get-Service -MockWith $mockGetService
29332857
}
29342858

2935-
It 'Should restart the service and dependent service' {
2936-
$null = Restart-ReportingServicesService -ServiceName 'ReportServer'
2859+
It 'Should restart the service and dependent service with wait time' {
2860+
$null = Restart-ReportingServicesService -ServiceName 'ReportServer' -WaitTime 1
29372861

29382862
Should -Invoke -CommandName Get-Service -ParameterFilter {
29392863
$Name -eq $mockServiceName
29402864
} -Scope It -Exactly -Times 1
29412865
Should -Invoke -CommandName Stop-Service -Scope It -Exactly -Times 1
29422866
Should -Invoke -CommandName Start-Service -Scope It -Exactly -Times 2
2867+
Should -Invoke -CommandName Start-Sleep -Scope It -Exactly -Times 1
29432868
}
2944-
29452869
}
29462870
}
29472871

0 commit comments

Comments
 (0)