1616 'WindowsServiceIdentityConfigured' and methods for managing Reporting
1717 Services configuration.
1818
19+ By default, if the CIM instance is not found on the first attempt, the
20+ command will retry after a delay. This handles intermittent failures
21+ when the Report Server service or WMI provider is not immediately ready.
22+ Use `-SkipRetry` to disable retry behavior.
23+
1924 . PARAMETER InstanceName
2025 Specifies the name of the Reporting Services instance. This is a
2126 mandatory parameter.
2530 If not specified, the version is automatically detected using
2631 `Get-SqlDscRSSetupConfiguration`.
2732
33+ . PARAMETER RetryCount
34+ Specifies the number of retry attempts if the CIM instance is not found.
35+ Default is 1 retry attempt.
36+
37+ . PARAMETER RetryDelaySeconds
38+ Specifies the delay in seconds between retry attempts. Default is 30
39+ seconds.
40+
41+ . PARAMETER SkipRetry
42+ If specified, skips retry attempts and throws an error immediately if
43+ the CIM instance is not found.
44+
2845 . EXAMPLE
2946 Get-SqlDscRSConfiguration -InstanceName 'SSRS'
3047
3148 Returns the configuration CIM instance for the SSRS instance. The version
32- is automatically detected.
49+ is automatically detected. Retries once after 30 seconds if not found.
3350
3451 . EXAMPLE
3552 Get-SqlDscRSConfiguration -InstanceName 'SSRS' -Version 15
4360 Gets the configuration CIM instance for the SSRS instance and enables
4461 secure connection using the pipeline.
4562
63+ . EXAMPLE
64+ Get-SqlDscRSConfiguration -InstanceName 'SSRS' -RetryCount 3 -RetryDelaySeconds 10
65+
66+ Returns the configuration CIM instance for the SSRS instance, retrying
67+ up to 3 times with a 10-second delay between attempts if not found.
68+
69+ . EXAMPLE
70+ Get-SqlDscRSConfiguration -InstanceName 'SSRS' -SkipRetry
71+
72+ Returns the configuration CIM instance for the SSRS instance without
73+ any retry attempts. Throws an error immediately if not found.
74+
4675 . INPUTS
4776 None.
4877
@@ -64,7 +93,21 @@ function Get-SqlDscRSConfiguration
6493
6594 [Parameter ()]
6695 [System.Int32 ]
67- $Version
96+ $Version ,
97+
98+ [Parameter ()]
99+ [ValidateRange (1 , [System.Int32 ]::MaxValue)]
100+ [System.Int32 ]
101+ $RetryCount = 1 ,
102+
103+ [Parameter ()]
104+ [ValidateRange (1 , [System.Int32 ]::MaxValue)]
105+ [System.Int32 ]
106+ $RetryDelaySeconds = 30 ,
107+
108+ [Parameter ()]
109+ [System.Management.Automation.SwitchParameter ]
110+ $SkipRetry
68111 )
69112
70113 if (-not $PSBoundParameters.ContainsKey (' Version' ))
@@ -102,25 +145,54 @@ function Get-SqlDscRSConfiguration
102145 ErrorAction = ' Stop'
103146 }
104147
105- try
148+ $maxAttempts = if ( $SkipRetry .IsPresent )
106149 {
107- $reportingServicesConfiguration = Get-CimInstance @getCimInstanceParameters
150+ 1
108151 }
109- catch
152+ else
110153 {
111- $errorMessage = $script :localizedData.Get_SqlDscRSConfiguration_FailedToGetConfiguration -f $InstanceName , $_.Exception.Message
154+ 1 + $RetryCount
155+ }
112156
113- $errorRecord = New-ErrorRecord - Exception (New-InvalidOperationException - Message $errorMessage - ErrorRecord $_ - PassThru) - ErrorId ' GSRSCD0003' - ErrorCategory ' InvalidOperation' - TargetObject $InstanceName
157+ $attempt = 0
158+ $reportingServicesConfiguration = $null
114159
115- $PSCmdlet.ThrowTerminatingError ($errorRecord )
116- }
160+ while ($attempt -lt $maxAttempts )
161+ {
162+ $attempt ++
163+
164+ try
165+ {
166+ $reportingServicesConfiguration = Get-CimInstance @getCimInstanceParameters
167+ }
168+ catch
169+ {
170+ $errorMessage = $script :localizedData.Get_SqlDscRSConfiguration_FailedToGetConfiguration -f $InstanceName , $_.Exception.Message
171+
172+ $errorRecord = New-ErrorRecord - Exception (New-InvalidOperationException - Message $errorMessage - ErrorRecord $_ - PassThru) - ErrorId ' GSRSCD0003' - ErrorCategory ' InvalidOperation' - TargetObject $InstanceName
173+
174+ $PSCmdlet.ThrowTerminatingError ($errorRecord )
175+ }
176+
177+ # Filter to ensure we get the correct instance if multiple are returned.
178+ $reportingServicesConfiguration = $reportingServicesConfiguration |
179+ Where-Object - FilterScript {
180+ $_.InstanceName -eq $InstanceName
181+ }
117182
118- # Filter to ensure we get the correct instance if multiple are returned.
119- $reportingServicesConfiguration = $reportingServicesConfiguration |
120- Where-Object - FilterScript {
121- $_.InstanceName -eq $InstanceName
183+ if ($reportingServicesConfiguration )
184+ {
185+ break
122186 }
123187
188+ if ($attempt -lt $maxAttempts )
189+ {
190+ Write-Debug - Message ($script :localizedData.Get_SqlDscRSConfiguration_RetryingAfterDelay -f $InstanceName , $attempt , $maxAttempts , $RetryDelaySeconds )
191+
192+ Start-Sleep - Seconds $RetryDelaySeconds
193+ }
194+ }
195+
124196 if (-not $reportingServicesConfiguration )
125197 {
126198 $errorMessage = $script :localizedData.Get_SqlDscRSConfiguration_ConfigurationNotFound -f $InstanceName
0 commit comments