From 321380b92c5d9c91a996258497a58529e44bd182 Mon Sep 17 00:00:00 2001 From: Nik Charlebois Date: Wed, 4 Jan 2023 11:23:04 -0500 Subject: [PATCH] FIXES #2728 --- CHANGELOG.md | 5 ++++ .../MSFT_SCRetentionCompliancePolicy.psm1 | 24 +++++++++++++++++- .../MSFT_SCRetentionComplianceRule.psm1 | 25 ++++++++++++++++++- 3 files changed, 52 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bee8290771..8f76d16390 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,11 @@ * SCRetentionCompliancePolicy * Forces changes to existing policies to be applied. FIXES [#2719](https://github.com/microsoft/Microsoft365DSC/issues/2719) + * Handles wait when the associated policy has pending changes. + FIXES [#2728](https://github.com/microsoft/Microsoft365DSC/issues/2728) +* SCRetentionComplianceRule + * Handles wait when the associated policy has pending changes. + FIXES [#2728](https://github.com/microsoft/Microsoft365DSC/issues/2728) * TeamsEmergencyCallingPolicy * Fixes issue where CertificateThumbprint wasn't working because Credential was set to mandatory by the Test-TargetResource function. FIXES [#2710](https://github.com/microsoft/Microsoft365DSC/issues/2710) diff --git a/Modules/Microsoft365DSC/DSCResources/MSFT_SCRetentionCompliancePolicy/MSFT_SCRetentionCompliancePolicy.psm1 b/Modules/Microsoft365DSC/DSCResources/MSFT_SCRetentionCompliancePolicy/MSFT_SCRetentionCompliancePolicy.psm1 index 2e47c6d3f7..65aaec38ae 100644 --- a/Modules/Microsoft365DSC/DSCResources/MSFT_SCRetentionCompliancePolicy/MSFT_SCRetentionCompliancePolicy.psm1 +++ b/Modules/Microsoft365DSC/DSCResources/MSFT_SCRetentionCompliancePolicy/MSFT_SCRetentionCompliancePolicy.psm1 @@ -768,7 +768,29 @@ function Set-TargetResource } Write-Verbose "Updating Policy with values: $(Convert-M365DscHashtableToString -Hashtable $CreationParams)" - Set-RetentionCompliancePolicy @CreationParams -Force + $success = $false + $retries = 1 + while (!$success -and $retries -le 10) + { + try + { + Set-RetentionCompliancePolicy @CreationParams -Force -ErrorAction Stop + $success = $true + } + catch + { + if ($_.Exception.Message -like "*are being deployed. Once deployed, additional actions can be performed*") + { + Write-Verbose -Message "The policy has pending changes being deployed. Waiting 30 seconds for a maximum of 300 seconds (5 minutes). Total time waited so far {$($retries * 30) seconds}" + Start-Sleep -Seconds 30 + } + else + { + $success = $true + } + } + $retries++ + } } elseif (('Absent' -eq $Ensure) -and ('Present' -eq $CurrentPolicy.Ensure)) { diff --git a/Modules/Microsoft365DSC/DSCResources/MSFT_SCRetentionComplianceRule/MSFT_SCRetentionComplianceRule.psm1 b/Modules/Microsoft365DSC/DSCResources/MSFT_SCRetentionComplianceRule/MSFT_SCRetentionComplianceRule.psm1 index 97d79de1fb..b802d3a750 100644 --- a/Modules/Microsoft365DSC/DSCResources/MSFT_SCRetentionComplianceRule/MSFT_SCRetentionComplianceRule.psm1 +++ b/Modules/Microsoft365DSC/DSCResources/MSFT_SCRetentionComplianceRule/MSFT_SCRetentionComplianceRule.psm1 @@ -303,7 +303,30 @@ function Set-TargetResource } Write-Verbose -Message "Updating RetentionComplianceRule with values:`r`n$(Convert-M365DscHashtableToString -Hashtable $CreationParams)" - Set-RetentionComplianceRule @CreationParams + + $success = $false + $retries = 1 + while (!$success -and $retries -le 10) + { + try + { + Set-RetentionComplianceRule @CreationParams -ErrorAction Stop + $success = $true + } + catch + { + if ($_.Exception.Message -like "*are being deployed. Once deployed, additional actions can be performed*") + { + Write-Verbose -Message "The associated policy has pending changes being deployed. Waiting 30 seconds for a maximum of 300 seconds (5 minutes). Total time waited so far {$($retries * 30) seconds}" + Start-Sleep -Seconds 30 + } + else + { + $success = $true + } + } + $retries++ + } } elseif (('Absent' -eq $Ensure) -and ('Present' -eq $CurrentPolicy.Ensure)) {