Why not use a group instead in the policy and add / remove mailboxes from that?
Using Set-RetentionCompliancePolicy to update AddExchangeLocationException and RemoveExchangeLocationException
mark terry
125
Reputation points
Hi folks,
We have a script which we use to exclude/include mailboxes from our Exchange Retention Policy. The script reads the email addresses of the respective mailboxes from a CSV file and then uses the Set-RetentionCompliancePolicy cmdlet with either the AddExchangeLocationException or RemoveExchangeLocationException switch to include or exclude those users from our Retention Policy.
The section of our script which does the above is as follows:
$mailboxes=Import-Csv C:\Retention-Policy\mailboxes-collected-data.csv
$mailboxes | foreach {Set-RetentionCompliancePolicy -Identity "DEV-Exchange Retention" -AddExchangeLocationException $_.PrimarySMTPAddress}
The input CSV file looks like this:
PrimarySmtpAddress
test1@test.org
test2@test.org
test2@test.org
This script was working fine up until a few weeks ago, but now when we run it, we get the error below:
Write-ErrorMessage : |Microsoft.Exchange.Management.UnifiedPolicy.PolicyLockConflictException|Previous changes to the policy '0398f611-4045-4413-a52d-13afd9ac63a0' are being deployed. Once
deployed, additional actions can be performed. Please refer to 'https://go.microsoft.com/fwlink/?linkid=2225070' to learn more.
At C:\Users\terry\AppData\Local\Temp\tmpEXO_jgv3gzjz.fax\tmpEXO_jgv3gzjz.fax.psm1:1190 char:13
+ Write-ErrorMessage $ErrorObject
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Set-RetentionCompliancePolicy], PolicyLockConflictException
+ FullyQualifiedErrorId : [TimeStamp=Tue, 31 Oct 2023 17:24:14 GMT],Write-ErrorMessage
It looks like it reads in the first entry of the CSV file but does not process the rest. Based on the above error message, it looks like it is having trouble processing multiple entries from the CSV file.
Any suggestions on how we can read in the mailboxes from our file so we can continue to set the AddExchangeLocationException and RemoveExchangeLocationException switches and update our Retention Policy?
Thanks!