Removing a list of users from a group and silently failing on specific entries
<p>I have the need to cleanup data between a database and an Active Directory.
To make the whole architecture simpler, let's just say that in my database, I have a list of groups, and their members.</p>

<p>In my AD, I also have groups, but I need to cleanup the memberships of these groups to be the same as the one in my database.</p>

<p>I came up with a simple solution that is to compare the list of members in my database with the one in my AD group, then make a differential to know which accounts I need to remove from the AD group, and which accounts I need to add to the group.</p>

<p>The problem is that the volume of users in my whole environment is pretty big and cause latency issues. During the treatment of the differential, the script failed with the error :</p>

<pre><code>Microsoft.ActiveDirectory.Management.ADException : The specified account name is not a member of the group
</code></pre>

<p>After some debugging it showed that in the duration of the script, some operations continue to run on AD and the database, and the member was removed from that group after the differential was established, causing the script to try to remove again that member of the group, causing the error. Due to the volume of users, the time between the differential and the end of treatment of that differential can be several hours.</p>

<p>Is there a way to silently fail for this entry, and this entry only, and continue to process the list of users, when the command is formatted as follow ?</p>

<pre><code>Remove-ADGroupMember -Identity $group -Member $users -Server $ADServer  -Credential $creds -Confirm:$false
</code></pre>

<p>We cannot realistically check the membership of the group between each operation to update the differential because the treatment time would be exponentially higher.</p>

<p>Also, related question, would that silent failing work when the account doesn't exist in AD anymore ?</p>