Powershell to exclude Group Members from Dynamic Distribution List

active-directorydistribution-listsdynamicfilterpowershell

I am attempting to remove specific users from a Dynamic Distribution List. I have searched and toyed with my PowerShell script for sometime with no luck. I'm sure it is something I am overlooking as I'm not too experienced with OPATH syntax. I've created this group within the EAC (2013) to include all email users internal and cloud.

When I do a:

Get-DynamicDistributionGroup –Identity “Email Users” | fl

It returns this as the RecipientFilter:

{((((RecipientType -eq 'UserMailbox') -or (RecipientType -eq
'MailUser'))) -and (-not(Name -like 'SystemMailbox{*')) -and
(-not(Name -like 'CAS_{*')) -and (-not(RecipientTypeDetailsValue -eq
'MailboxPlan')) -and (-not(RecipientTypeDetailsValue -eq
'DiscoveryMailbox')) -and (-not(RecipientTypeDetailsValue -eq
'PublicFolderMailbox')) -and (-not(RecipientTypeDetailsValue -eq
'ArbitrationMailbox')))}

I would like to exclude all members of the group DDGExclude. I've tried adding the following onto the command with no luck.

-and (-not(MemberOfGroup -eq ‘DDGExclude’))

I would also like to understand how can I exclude users that have the ExtensionCustomAttribute10 as NOSYNC. I have tried the following with no luck.

-and (ExtensionCustomAttribute10 -ne “NOSYNC”) 

Any help would be much appreciated.

Best Answer

One thing to do is not use invalid characters on the PowerShell commands.

-and (-not(MemberOfGroup -eq ‘DDGExclude’))  

should be:

-and (-not(MemberOfGroup -eq 'DDGExclude'))  

Also:

-and (ExtensionCustomAttribute10 -ne “NOSYNC”)  

should be:

-and (ExtensionCustomAttribute10 -ne "NOSYNC")  
Related Topic