1

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.

Greg Askew
  • 34,339
  • 3
  • 52
  • 81
Jim
  • 17
  • 3
  • 6
  • Just to clarify what you mean by "with no luck", the dynamic distribution list contains the system mailboxes (which you're trying to exclude) as well as the users with "NOSYNC" in ExtensionAttribute10 (which you're also trying to exclude)? – Matt Dec 08 '15 at 22:18
  • Meaning that the command would not take. I would get various errors within Powershell. Right now, the DDL has all user objects with mailboxes. But I'd like to exclude a certain group or users with the custom attribute value. – Jim Dec 08 '15 at 22:27
  • Can you post the errors you are getting? – Matt Dec 08 '15 at 22:55
  • Do you write your PowerShell scripts in Word, or where do those orthographically correct, but programmatically wrong quotes come from? :D **OnTopic**: Do you run Office 365 in a hybrid deployment? – Daniel Dec 09 '15 at 16:46
  • I'll correct the quotes as listed below and run it again. Yes, it is a hybrid mail environment. – Jim Dec 10 '15 at 17:21

1 Answers1

2

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")  
Greg Askew
  • 34,339
  • 3
  • 52
  • 81
  • Greg, you are fantastic! That was it. Set-DynamicDistributionGroup -Identity "Email Users" -RecipientFilter {((RecipientType -eq 'UserMailbox') -or (RecipientType -eq 'MailUser')) -and (-not(MemberOfGroup -eq "DDGExclude"))} – Jim Dec 10 '15 at 17:38
  • I wanted to clarify incase others look at this thread for help. When using the MemberOfGroup, just the group name won't work, I had to reference the complete DN name. – Jim Dec 14 '15 at 19:26