@@ -1058,26 +1058,13 @@ function Set-TargetResource
1058
1058
)
1059
1059
1060
1060
$restartReportingService = $true
1061
+ $restoreKey = $false
1062
+ $reportingServicesInitialized = $reportingServicesData.Configuration.IsInitialized
1061
1063
1062
- $invokeRsCimMethodInitializeReportServerParameters = @ {
1063
- CimInstance = $reportingServicesData.Configuration
1064
- MethodName = ' InitializeReportServer'
1065
- Arguments = @ {
1066
- InstallationId = $reportingServicesData.Configuration.InstallationID
1067
- }
1068
- }
1069
-
1070
- try
1064
+ do
1071
1065
{
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 )
1077
1067
{
1078
- Write-Verbose - Message ' Received a runtime exception' - Verbose
1079
-
1080
- # Restore key here
1081
1068
$invokeRsCimMethodRestoreEncryptionKeyParameters = @ {
1082
1069
CimInstance = $reportingServicesData.Configuration
1083
1070
MethodName = ' RestoreEncryptionKey'
@@ -1089,18 +1076,38 @@ function Set-TargetResource
1089
1076
}
1090
1077
1091
1078
$restoreEncryptionKeyResult = Invoke-RsCimMethod @invokeRsCimMethodRestoreEncryptionKeyParameters
1079
+ }
1092
1080
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
+ }
1097
1089
}
1090
+
1091
+ $initializeReportServerResult = Invoke-RsCimMethod @invokeRsCimMethodInitializeReportServerParameters
1092
+ $reportingServicesInitialized = $initializeReportServerResult.ReturnValue
1098
1093
}
1099
- else
1094
+ catch [ System.Management.Automation.RuntimeException ]
1100
1095
{
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
+ }
1102
1105
}
1103
1106
}
1107
+ while ( -not $reportingServicesInitialized )
1108
+
1109
+ # Refresh the reportingServicesData
1110
+ $reportingServicesData = Get-ReportingServicesData - InstanceName $InstanceName
1104
1111
}
1105
1112
else
1106
1113
{
0 commit comments