Using Set-RetentionCompliancePolicy to update AddExchangeLocationException and RemoveExchangeLocationException

mark terry 25 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:


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 '' 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?


Exchange Server Management
Exchange Server Management
Exchange Server: A family of Microsoft client/server messaging and collaboration software.Management: The act or process of organizing, handling, directing or controlling something.
7,012 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Andy David - MVP 133.8K Reputation points MVP

    Why not use a group instead in the policy and add / remove mailboxes from that?

    User's image