Skip to content

Add commands for Start/Stop Report Server#2412

Merged
johlju merged 2 commits intodsccommunity:mainfrom
johlju:f/add-rs-startstop-commands
Jan 16, 2026
Merged

Add commands for Start/Stop Report Server#2412
johlju merged 2 commits intodsccommunity:mainfrom
johlju:f/add-rs-startstop-commands

Conversation

@johlju
Copy link
Copy Markdown
Member

@johlju johlju commented Jan 16, 2026

Pull Request (PR) description

  • Added public commands Start-SqlDscRSWindowsService, Stop-SqlDscRSWindowsService, Start-SqlDscRSWebService, and Stop-SqlDscRSWebService to manage Reporting Services Windows and web services using the SetServiceState WMI method.

This Pull Request (PR) fixes the following issues

None.

Task list

  • Added an entry to the change log under the Unreleased section of the
    file CHANGELOG.md. Entry should say what was changed and how that
    affects users (if applicable), and reference the issue being resolved
    (if applicable).
  • Resource documentation updated in the resource's README.md.
  • Resource parameter descriptions updated in schema.mof.
  • Comment-based help updated, including parameter descriptions.
  • Localization strings updated.
  • Examples updated.
  • Unit tests updated. See DSC Community Testing Guidelines.
  • Integration tests updated (where possible). See DSC Community Testing Guidelines.
  • Code changes adheres to DSC Community Style Guidelines.

This change is Reviewable

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jan 16, 2026

Caution

Review failed

The pull request is closed.

Walkthrough

Adds four public cmdlets to start/stop SQL Server Reporting Services and Power BI Report Server Windows and Web services through the WMI SetServiceState method, a private Get-RSServiceState helper, localized strings, unit and integration tests, and CI pipeline entries to run the new integration tests.

Changes

Cohort / File(s) Summary
Public RS Service Commands
source/Public/Start-SqlDscRSWindowsService.ps1, source/Public/Stop-SqlDscRSWindowsService.ps1, source/Public/Start-SqlDscRSWebService.ps1, source/Public/Stop-SqlDscRSWebService.ps1
Four new cmdlets implementing start/stop control for RS Windows and Web services. Accept pipeline Configuration, optional -Force, use ShouldProcess, call Get-RSServiceState to build args, invoke SetServiceState via Invoke-RsCimMethod, and produce standardized terminating errors on failure.
Service State Helper
source/Private/Get-RSServiceState.ps1
New private function that reads provided configuration, computes current and requested Enable/Disable values for Windows and Web services, and returns a hashtable with EnableWindowsService, EnableWebService, and EnableReportManager.
Localization Strings
source/en-US/SqlServerDsc.strings.psd1
Adds string resources for service-state reporting, ShouldProcess captions/descriptions, confirmations, verbose messages, and failure texts for the four commands and the helper.
Unit Tests
tests/Unit/Private/Get-RSServiceState.Tests.ps1, tests/Unit/Public/Start-SqlDscRSWindowsService.Tests.ps1, tests/Unit/Public/Stop-SqlDscRSWindowsService.Tests.ps1, tests/Unit/Public/Start-SqlDscRSWebService.Tests.ps1, tests/Unit/Public/Stop-SqlDscRSWebService.Tests.ps1
New Pester unit tests covering parameter sets, success paths, -Force, -WhatIf, explicit configuration input, error handling, and call-count assertions (mocks for Get-RSServiceState and Invoke-RsCimMethod).
Integration Tests
tests/Integration/Commands/Start-SqlDscRSWindowsService.Integration.Tests.ps1, tests/Integration/Commands/Stop-SqlDscRSWindowsService.Integration.Tests.ps1, tests/Integration/Commands/Start-SqlDscRSWebService.Integration.Tests.ps1, tests/Integration/Commands/Stop-SqlDscRSWebService.Integration.Tests.ps1
New integration suites exercising start/stop across SSRS 2017/2019/2022 and Power BI Report Server, asserting no throws, correct service state changes, and idempotency.
CI Pipeline
azure-pipelines.yml
Appends the four new integration test scripts to Group 9 lists in SQL Server and BI/Power BI Reporting Services integration stages.
Changelog
CHANGELOG.md
Documents addition of the four public commands and supporting changes.
Minor test tweak
tests/Integration/Commands/Remove-SqlDscRSEncryptedInformation.Integration.Tests.ps1
Reduced post-key-removal sleep from 300s to 120s and added a verbose progress message.

Sequence Diagram(s)

sequenceDiagram
    participant User as User/Cmdlet
    participant Cmd as Start/Stop<br/>Cmdlet
    participant Helper as Get-RSServiceState
    participant Invoker as Invoke-RsCimMethod
    participant WMI as SetServiceState<br/>(WMI)
    participant Service as RS Service

    User->>Cmd: Invoke with Configuration (and optional -Force)
    Cmd->>Cmd: ShouldProcess / confirmation
    Cmd->>Helper: Get-RSServiceState (Enable/Disable switch)
    Helper-->>Cmd: Hashtable (EnableWindowsService, EnableWebService,...)
    Cmd->>Invoker: Invoke-RsCimMethod MethodName='SetServiceState' with args
    Invoker->>WMI: CIM method call
    WMI->>Service: Start/Stop Windows or Web service
    Service-->>WMI: Operation result
    WMI-->>Invoker: Return result
    Invoker-->>Cmd: Success or throw
    Cmd-->>User: Complete or terminate with error
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: adding commands for starting and stopping Report Server services.
Description check ✅ Passed The description is directly related to the changeset, detailing the four new commands added for managing Reporting Services.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@johlju johlju added the needs review The pull request needs a code review. label Jan 16, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Jan 16, 2026

Codecov Report

❌ Patch coverage is 82.22222% with 16 lines in your changes missing coverage. Please review.
✅ Project coverage is 94%. Comparing base (70c5846) to head (27c88d8).

Files with missing lines Patch % Lines
source/Public/Start-SqlDscRSWebService.ps1 77% 4 Missing ⚠️
source/Public/Start-SqlDscRSWindowsService.ps1 77% 4 Missing ⚠️
source/Public/Stop-SqlDscRSWebService.ps1 77% 4 Missing ⚠️
source/Public/Stop-SqlDscRSWindowsService.ps1 77% 4 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@          Coverage Diff          @@
##            main   #2412   +/-   ##
=====================================
- Coverage     94%     94%   -1%     
=====================================
  Files        218     223    +5     
  Lines      10981   11071   +90     
=====================================
+ Hits       10358   10432   +74     
- Misses       623     639   +16     
Flag Coverage Δ
unit 94% <82%> (-1%) ⬇️
Files with missing lines Coverage Δ
source/Private/Get-RSServiceState.ps1 100% <100%> (ø)
source/Public/Start-SqlDscRSWebService.ps1 77% <77%> (ø)
source/Public/Start-SqlDscRSWindowsService.ps1 77% <77%> (ø)
source/Public/Stop-SqlDscRSWebService.ps1 77% <77%> (ø)
source/Public/Stop-SqlDscRSWindowsService.ps1 77% <77%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@johlju johlju marked this pull request as ready for review January 16, 2026 20:16
@johlju johlju requested a review from a team as a code owner January 16, 2026 20:16
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Fix all issues with AI agents
In `@CHANGELOG.md`:
- Line 10: Condense and wrap the long changelog bullet into a short, wrapped
entry (<=80 chars per line) for the Unreleased "Added" list: replace the current
sentence with a concise line that groups the four commands and their purpose,
e.g. mention the commands Start-SqlDscRSWindowsService,
Stop-SqlDscRSWindowsService, Start-SqlDscRSWebService, Stop-SqlDscRSWebService
and that they manage Reporting Services Windows/web services via
SetServiceState; keep it one brief bullet and hard-wrap to 80 characters.

In `@tests/Unit/Public/Start-SqlDscRSWebService.Tests.ps1`:
- Around line 89-90: Replace the Should -Not -Throw pattern by invoking
Start-SqlDscRSWebService directly and discarding its output into $null;
specifically, update the test cases that call Start-SqlDscRSWebService (e.g.,
the block currently using "{ $mockCimInstance | Start-SqlDscRSWebService
-Confirm:$false } | Should -Not -Throw") to call "$null = $mockCimInstance |
Start-SqlDscRSWebService -Confirm:$false" (and do the same for the other
occurrences around the other test cases referencing Start-SqlDscRSWebService) so
the command runs directly without using Should -Not -Throw per test guidelines.
- Around line 46-64: Add a new unit test after the parameter set assertions for
Start-SqlDscRSWebService that validates key parameter attributes: use
Get-Command -Name 'Start-SqlDscRSWebService' to retrieve the command, then
inspect its .Parameters['Configuration'] (and other params like 'Force') and
assert their attributes (e.g., Mandatory, ValueFromPipeline) match expectations;
implement a table-driven It block that iterates expected parameter names and
expected attribute values and uses Should assertions to compare the actual
parameter.Attributes properties to the expected Mandatory/ValueFromPipeline
settings.
🧹 Nitpick comments (9)
source/Private/Get-RSServiceState.ps1 (1)

31-52: Missing .INPUTS section in comment-based help.

As per coding guidelines, comment-based help must include an .INPUTS section. Since this function does not accept pipeline input, specify None..

📝 Proposed fix
     .OUTPUTS
         System.Collections.Hashtable

         Returns a hashtable with the following keys:
         - EnableWindowsService: Boolean value for the Windows service state.
         - EnableWebService: Boolean value for the web service state.
         - EnableReportManager: Boolean value (deprecated, always matches EnableWebService).

+    .INPUTS
+        None.
+
     .EXAMPLE
tests/Unit/Public/Stop-SqlDscRSWebService.Tests.ps1 (3)

89-100: Avoid Should -Not -Throw; invoke commands directly.

Per coding guidelines, tests should invoke commands directly and let Pester report any unexpected failures naturally rather than wrapping in Should -Not -Throw.

♻️ Proposed fix
         It 'Should stop web service without errors' {
-            { $mockCimInstance | Stop-SqlDscRSWebService -Confirm:$false } | Should -Not -Throw
+            $null = $mockCimInstance | Stop-SqlDscRSWebService -Confirm:$false

             Should -Invoke -CommandName Get-RSServiceState -ParameterFilter {
                 $DisableWebService -eq $true
             } -Exactly -Times 1

             Should -Invoke -CommandName Invoke-RsCimMethod -ParameterFilter {
                 $MethodName -eq 'SetServiceState' -and
                 $Arguments.EnableWebService -eq $false
             } -Exactly -Times 1
         }

132-136: Avoid Should -Not -Throw.

♻️ Proposed fix
         It 'Should stop web service without confirmation' {
-            { $mockCimInstance | Stop-SqlDscRSWebService -Force } | Should -Not -Throw
+            $null = $mockCimInstance | Stop-SqlDscRSWebService -Force

             Should -Invoke -CommandName Invoke-RsCimMethod -Exactly -Times 1
         }

182-186: Avoid Should -Not -Throw.

♻️ Proposed fix
         It 'Should stop web service' {
-            { Stop-SqlDscRSWebService -Configuration $mockCimInstance -Confirm:$false } | Should -Not -Throw
+            $null = Stop-SqlDscRSWebService -Configuration $mockCimInstance -Confirm:$false

             Should -Invoke -CommandName Invoke-RsCimMethod -Exactly -Times 1
         }
tests/Integration/Commands/Start-SqlDscRSWindowsService.Integration.Tests.ps1 (1)

36-52: Avoid Should -Not -Throw; invoke commands directly.

Per coding guidelines, integration tests should invoke commands directly. The pattern repeats across all contexts in this file.

♻️ Proposed fix for all test cases
         It 'Should start Windows service using pipeline' {
             $config = Get-SqlDscRSConfiguration -InstanceName 'SSRS'
-            { $config | Start-SqlDscRSWindowsService -Force -ErrorAction 'Stop' } | Should -Not -Throw
+            $null = $config | Start-SqlDscRSWindowsService -Force -ErrorAction 'Stop'

             # Verify Windows service is started
             $verifyConfig = Get-SqlDscRSConfiguration -InstanceName 'SSRS'
             $verifyConfig.IsWindowsServiceEnabled | Should -BeTrue
         }

         It 'Should be idempotent when Windows service is already started' {
             $config = Get-SqlDscRSConfiguration -InstanceName 'SSRS'
-            { $config | Start-SqlDscRSWindowsService -Force -ErrorAction 'Stop' } | Should -Not -Throw
+            $null = $config | Start-SqlDscRSWindowsService -Force -ErrorAction 'Stop'

             # Verify Windows service is still started
             $verifyConfig = Get-SqlDscRSConfiguration -InstanceName 'SSRS'
             $verifyConfig.IsWindowsServiceEnabled | Should -BeTrue
         }

Apply the same pattern to all remaining contexts (SQL2019_RS, SQL2022_RS, PowerBI).

tests/Integration/Commands/Stop-SqlDscRSWindowsService.Integration.Tests.ps1 (1)

36-52: Avoid Should -Not -Throw; invoke commands directly.

Same pattern as the Start tests. Apply the fix across all contexts.

♻️ Proposed fix for all test cases
         It 'Should stop Windows service using pipeline' {
             $config = Get-SqlDscRSConfiguration -InstanceName 'SSRS'
-            { $config | Stop-SqlDscRSWindowsService -Force -ErrorAction 'Stop' } | Should -Not -Throw
+            $null = $config | Stop-SqlDscRSWindowsService -Force -ErrorAction 'Stop'

             # Verify Windows service is stopped
             $verifyConfig = Get-SqlDscRSConfiguration -InstanceName 'SSRS'
             $verifyConfig.IsWindowsServiceEnabled | Should -BeFalse
         }

         It 'Should be idempotent when Windows service is already stopped' {
             $config = Get-SqlDscRSConfiguration -InstanceName 'SSRS'
-            { $config | Stop-SqlDscRSWindowsService -Force -ErrorAction 'Stop' } | Should -Not -Throw
+            $null = $config | Stop-SqlDscRSWindowsService -Force -ErrorAction 'Stop'

             # Verify Windows service is still stopped
             $verifyConfig = Get-SqlDscRSConfiguration -InstanceName 'SSRS'
             $verifyConfig.IsWindowsServiceEnabled | Should -BeFalse
         }

Apply to all remaining contexts (SQL2019_RS, SQL2022_RS, PowerBI).

tests/Unit/Public/Start-SqlDscRSWindowsService.Tests.ps1 (3)

89-100: Avoid Should -Not -Throw - invoke commands directly.

Per coding guidelines, Should -Not -Throw should not be used. Instead, invoke the command directly. If the command throws, the test will fail naturally.

♻️ Suggested refactor
         It 'Should start Windows service without errors' {
-            { $mockCimInstance | Start-SqlDscRSWindowsService -Confirm:$false } | Should -Not -Throw
+            $null = $mockCimInstance | Start-SqlDscRSWindowsService -Confirm:$false

             Should -Invoke -CommandName Get-RSServiceState -ParameterFilter {
                 $EnableWindowsService -eq $true
             } -Exactly -Times 1

             Should -Invoke -CommandName Invoke-RsCimMethod -ParameterFilter {
                 $MethodName -eq 'SetServiceState' -and
                 $Arguments.EnableWindowsService -eq $true
             } -Exactly -Times 1
         }

132-136: Avoid Should -Not -Throw - invoke commands directly.

Same issue as above. Invoke the command directly instead of using Should -Not -Throw.

♻️ Suggested refactor
         It 'Should start Windows service without confirmation' {
-            { $mockCimInstance | Start-SqlDscRSWindowsService -Force } | Should -Not -Throw
+            $null = $mockCimInstance | Start-SqlDscRSWindowsService -Force

             Should -Invoke -CommandName Invoke-RsCimMethod -Exactly -Times 1
         }

182-186: Avoid Should -Not -Throw - invoke commands directly.

Same pattern as the other contexts. Invoke the command directly.

♻️ Suggested refactor
         It 'Should start Windows service' {
-            { Start-SqlDscRSWindowsService -Configuration $mockCimInstance -Confirm:$false } | Should -Not -Throw
+            $null = Start-SqlDscRSWindowsService -Configuration $mockCimInstance -Confirm:$false

             Should -Invoke -CommandName Invoke-RsCimMethod -Exactly -Times 1
         }

Comment thread CHANGELOG.md
Comment thread tests/Unit/Public/Start-SqlDscRSWebService.Tests.ps1
Comment thread tests/Unit/Public/Start-SqlDscRSWebService.Tests.ps1 Outdated
@johlju johlju merged commit f583104 into dsccommunity:main Jan 16, 2026
2 of 4 checks passed
@johlju johlju deleted the f/add-rs-startstop-commands branch January 16, 2026 20:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs review The pull request needs a code review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant