Skip to content

Commit c9c86c3

Browse files
committed
Updated initialize logic
1 parent 728049c commit c9c86c3

File tree

2 files changed

+31
-23
lines changed

2 files changed

+31
-23
lines changed

source/DSCResources/DSC_SqlRS/DSC_SqlRS.psm1

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,26 +1058,13 @@ function Set-TargetResource
10581058
)
10591059

10601060
$restartReportingService = $true
1061+
$restoreKey = $false
1062+
$reportingServicesInitialized = $reportingServicesData.Configuration.IsInitialized
10611063

1062-
$invokeRsCimMethodInitializeReportServerParameters = @{
1063-
CimInstance = $reportingServicesData.Configuration
1064-
MethodName = 'InitializeReportServer'
1065-
Arguments = @{
1066-
InstallationId = $reportingServicesData.Configuration.InstallationID
1067-
}
1068-
}
1069-
1070-
try
1064+
do
10711065
{
1072-
Invoke-RsCimMethod @invokeRsCimMethodInitializeReportServerParameters
1073-
}
1074-
catch [System.Management.Automation.RuntimeException]
1075-
{
1076-
if ( $_.Exception -match 'The report server was unable to validate the integrity of encrypted data in the database' )
1066+
if ( $restoreKey )
10771067
{
1078-
Write-Verbose -Message 'Received a runtime exception' -Verbose
1079-
1080-
# Restore key here
10811068
$invokeRsCimMethodRestoreEncryptionKeyParameters = @{
10821069
CimInstance = $reportingServicesData.Configuration
10831070
MethodName = 'RestoreEncryptionKey'
@@ -1089,18 +1076,38 @@ function Set-TargetResource
10891076
}
10901077

10911078
$restoreEncryptionKeyResult = Invoke-RsCimMethod @invokeRsCimMethodRestoreEncryptionKeyParameters
1079+
}
10921080

1093-
if ( $restoreEncryptionKeyResult.HRESULT -eq 0 )
1094-
{
1095-
# Finally, try and initialize the server again
1096-
Invoke-RsCimMethod @invokeRsCimMethodInitializeReportServerParameters
1081+
try
1082+
{
1083+
$invokeRsCimMethodInitializeReportServerParameters = @{
1084+
CimInstance = $reportingServicesData.Configuration
1085+
MethodName = 'InitializeReportServer'
1086+
Arguments = @{
1087+
InstallationId = $reportingServicesData.Configuration.InstallationID
1088+
}
10971089
}
1090+
1091+
$initializeReportServerResult = Invoke-RsCimMethod @invokeRsCimMethodInitializeReportServerParameters
1092+
$reportingServicesInitialized = $initializeReportServerResult.ReturnValue
10981093
}
1099-
else
1094+
catch [System.Management.Automation.RuntimeException]
11001095
{
1101-
throw $_
1096+
if ( $_.Exception -match 'The report server was unable to validate the integrity of encrypted data in the database' )
1097+
{
1098+
# Restore the encryption key before trying again
1099+
$restoreKey = $true
1100+
}
1101+
else
1102+
{
1103+
throw $_
1104+
}
11021105
}
11031106
}
1107+
while ( -not $reportingServicesInitialized )
1108+
1109+
# Refresh the reportingServicesData
1110+
$reportingServicesData = Get-ReportingServicesData -InstanceName $InstanceName
11041111
}
11051112
else
11061113
{

tests/Unit/DSC_SqlRS.Tests.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,7 @@ Describe 'SqlRS\Set-TargetResource' -Tag 'Set' {
606606
$mockInvokeRsCimMethod_InitializeReportServer = {
607607
return @{
608608
HRESULT = 0
609+
ReturnValue = $true
609610
}
610611
}
611612

0 commit comments

Comments
 (0)