Skip to content

Commit 10871a9

Browse files
authored
*-SqlDscRSUnattendedExecutionAccount: Add new commands (#2410)
1 parent 7af9141 commit 10871a9

26 files changed

+1448
-130
lines changed

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@
110110
"checkpointing",
111111
"HRESULT",
112112
"RSDB",
113-
"RSIP"
113+
"RSIP",
114+
"contoso"
114115
],
115116
"cSpell.ignorePaths": [
116117
".git"

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
244244
by calling the `InitializeReportServer` CIM method. Used to complete initial
245245
configuration after database and URL setup
246246
([issue #2014](https://github.com/dsccommunity/SqlServerDsc/issues/2014)).
247+
- Added public commands `Set-SqlDscRSUnattendedExecutionAccount` and
248+
`Remove-SqlDscRSUnattendedExecutionAccount` to manage the unattended execution
249+
account for Reporting Services. These wrap the `SetUnattendedExecutionAccount`
250+
CIM method.
247251
- Added public command `Get-SqlDscRSSslCertificate` to list available SSL
248252
certificates that can be used for Reporting Services. Wraps the
249253
`ListSSLCertificates` CIM method.
@@ -338,6 +342,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
338342
- Prerequisites Integration Tests
339343
- Added `svc-RS` local Windows user for Reporting Services service account
340344
integration testing.
345+
- `Get-SqlDscRSConfiguration`
346+
- Added retry logic with parameters `RetryCount`, `RetryDelaySeconds`, and
347+
`SkipRetry` to handle intermittent CIM instance retrieval failures when
348+
the Report Server service or WMI provider is not immediately ready.
341349

342350
### Fixed
343351

azure-pipelines.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,9 @@ stages:
594594
'tests/Integration/Commands/Get-SqlDscRSServiceAccount.Integration.Tests.ps1'
595595
'tests/Integration/Commands/Post.ServiceAccountChange.SQL2017.RS.Integration.Tests.ps1'
596596
'tests/Integration/Commands/Post.ServiceAccountChange.SQL2019-2022.RS.Integration.Tests.ps1'
597+
# Group 7
598+
'tests/Integration/Commands/Set-SqlDscRSUnattendedExecutionAccount.Integration.Tests.ps1'
599+
'tests/Integration/Commands/Remove-SqlDscRSUnattendedExecutionAccount.Integration.Tests.ps1'
597600
# Group 8
598601
'tests/Integration/Commands/Repair-SqlDscReportingService.Integration.Tests.ps1'
599602
'tests/Integration/Commands/Remove-SqlDscRSUrlReservation.Integration.Tests.ps1'
@@ -693,6 +696,9 @@ stages:
693696
'tests/Integration/Commands/Set-SqlDscRSServiceAccount.Integration.Tests.ps1'
694697
'tests/Integration/Commands/Get-SqlDscRSServiceAccount.Integration.Tests.ps1'
695698
'tests/Integration/Commands/Post.ServiceAccountChange.PowerBI.RS.Integration.Tests.ps1'
699+
# Group 7
700+
'tests/Integration/Commands/Set-SqlDscRSUnattendedExecutionAccount.Integration.Tests.ps1'
701+
'tests/Integration/Commands/Remove-SqlDscRSUnattendedExecutionAccount.Integration.Tests.ps1'
696702
# Group 8
697703
'tests/Integration/Commands/Repair-SqlDscPowerBIReportServer.Integration.Tests.ps1'
698704
'tests/Integration/Commands/Remove-SqlDscRSUrlReservation.Integration.Tests.ps1'
@@ -778,6 +784,9 @@ stages:
778784
'tests/Integration/Commands/Get-SqlDscRSSslCertificateBinding.Integration.Tests.ps1'
779785
'tests/Integration/Commands/Remove-SqlDscRSSslCertificateBinding.Integration.Tests.ps1'
780786
'tests/Integration/Commands/Set-SqlDscRSSslCertificateBinding.Integration.Tests.ps1'
787+
# Group 7
788+
'tests/Integration/Commands/Set-SqlDscRSUnattendedExecutionAccount.Integration.Tests.ps1'
789+
'tests/Integration/Commands/Remove-SqlDscRSUnattendedExecutionAccount.Integration.Tests.ps1'
781790
)
782791
name: test
783792
displayName: 'Run Integration Test'
@@ -1196,6 +1205,7 @@ stages:
11961205
- Integration_Test_Commands_SqlServer_PreparedImage
11971206
- Integration_Test_Commands_ReportingServices
11981207
- Integration_Test_Commands_BIReportServer
1208+
- Integration_Test_Commands_BIReportServer_Secure
11991209
- Integration_Test_Resources_SqlServer
12001210
- Integration_Test_Resources_SqlServer_dbatools
12011211
- Integration_Test_Resources_ReportingServices

source/Public/Add-SqlDscRSSslCertificateBinding.ps1

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -171,14 +171,13 @@ function Add-SqlDscRSSslCertificateBinding
171171
}
172172
catch
173173
{
174-
$PSCmdlet.ThrowTerminatingError(
175-
[System.Management.Automation.ErrorRecord]::new(
176-
($script:localizedData.Add_SqlDscRSSslCertificateBinding_FailedToAdd -f $instanceName, $_.Exception.Message),
177-
'ASRSSCB0001',
178-
[System.Management.Automation.ErrorCategory]::InvalidOperation,
179-
$Configuration
180-
)
181-
)
174+
$errorMessage = $script:localizedData.Add_SqlDscRSSslCertificateBinding_FailedToAdd -f $instanceName, $_.Exception.Message
175+
176+
$exception = New-InvalidOperationException -Message $errorMessage -ErrorRecord $_ -PassThru
177+
178+
$errorRecord = New-ErrorRecord -Exception $exception -ErrorId 'ASRSSCB0001' -ErrorCategory 'InvalidOperation' -TargetObject $Configuration
179+
180+
$PSCmdlet.ThrowTerminatingError($errorRecord)
182181
}
183182
}
184183

source/Public/Get-SqlDscRSConfiguration.ps1

Lines changed: 85 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
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.
@@ -25,11 +30,23 @@
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
@@ -43,6 +60,18 @@
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

source/Public/Get-SqlDscRSSslCertificate.ps1

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,13 @@ function Get-SqlDscRSSslCertificate
9797
}
9898
catch
9999
{
100-
$PSCmdlet.ThrowTerminatingError(
101-
[System.Management.Automation.ErrorRecord]::new(
102-
($script:localizedData.Get_SqlDscRSSslCertificate_FailedToGet -f $instanceName, $_.Exception.Message),
103-
'GSRSSC0001',
104-
[System.Management.Automation.ErrorCategory]::InvalidOperation,
105-
$Configuration
106-
)
107-
)
100+
$errorMessage = $script:localizedData.Get_SqlDscRSSslCertificate_FailedToGet -f $instanceName, $_.Exception.Message
101+
102+
$exception = New-InvalidOperationException -Message $errorMessage -ErrorRecord $_ -PassThru
103+
104+
$errorRecord = New-ErrorRecord -Exception $exception -ErrorId 'GSRSSC0001' -ErrorCategory 'InvalidOperation' -TargetObject $Configuration
105+
106+
$PSCmdlet.ThrowTerminatingError($errorRecord)
108107
}
109108
}
110109
}

source/Public/Get-SqlDscRSSslCertificateBinding.ps1

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -115,14 +115,13 @@ function Get-SqlDscRSSslCertificateBinding
115115
}
116116
catch
117117
{
118-
$PSCmdlet.ThrowTerminatingError(
119-
[System.Management.Automation.ErrorRecord]::new(
120-
($script:localizedData.Get_SqlDscRSSslCertificateBinding_FailedToGet -f $instanceName, $_.Exception.Message),
121-
'GSRSSCB0001',
122-
[System.Management.Automation.ErrorCategory]::InvalidOperation,
123-
$Configuration
124-
)
125-
)
118+
$errorMessage = $script:localizedData.Get_SqlDscRSSslCertificateBinding_FailedToGet -f $instanceName, $_.Exception.Message
119+
120+
$exception = New-InvalidOperationException -Message $errorMessage -ErrorRecord $_ -PassThru
121+
122+
$errorRecord = New-ErrorRecord -Exception $exception -ErrorId 'GSRSSCB0001' -ErrorCategory 'InvalidOperation' -TargetObject $Configuration
123+
124+
$PSCmdlet.ThrowTerminatingError($errorRecord)
126125
}
127126
}
128127
}

source/Public/Remove-SqlDscRSSslCertificateBinding.ps1

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ function Remove-SqlDscRSSslCertificateBinding
9292
{
9393
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('UseSyntacticallyCorrectExamples', '', Justification = 'Because the examples use pipeline input the rule cannot validate.')]
9494
[CmdletBinding(SupportsShouldProcess = $true, ConfirmImpact = 'Medium')]
95-
[OutputType([System.Object])]
95+
[OutputType([Microsoft.Management.Infrastructure.CimInstance])]
9696
param
9797
(
9898
[Parameter(Mandatory = $true, ValueFromPipeline = $true)]
@@ -169,14 +169,13 @@ function Remove-SqlDscRSSslCertificateBinding
169169
}
170170
catch
171171
{
172-
$PSCmdlet.ThrowTerminatingError(
173-
[System.Management.Automation.ErrorRecord]::new(
174-
($script:localizedData.Remove_SqlDscRSSslCertificateBinding_FailedToRemove -f $instanceName, $_.Exception.Message),
175-
'RSRSSCB0001',
176-
[System.Management.Automation.ErrorCategory]::InvalidOperation,
177-
$Configuration
178-
)
179-
)
172+
$errorMessage = $script:localizedData.Remove_SqlDscRSSslCertificateBinding_FailedToRemove -f $instanceName, $_.Exception.Message
173+
174+
$exception = New-InvalidOperationException -Message $errorMessage -ErrorRecord $_ -PassThru
175+
176+
$errorRecord = New-ErrorRecord -Exception $exception -ErrorId 'RSRSSCB0001' -ErrorCategory 'InvalidOperation' -TargetObject $Configuration
177+
178+
$PSCmdlet.ThrowTerminatingError($errorRecord)
180179
}
181180
}
182181

0 commit comments

Comments
 (0)