New DDL creation

Austin Sundar 436 Reputation points
2021-06-09T10:53:40.853+00:00

i am trying to create a new DL and it shows error . could anyone please help?

$DDL = “”
$Alias = “”
$OU = “”
New-DynamicDistributionGroup -Name $DDL -Alias $Alias -OrganizationalUnit $OU -RecipientFilter ((RecipientTypeDetails -eq 'UserMailbox') -and (Office -eq 'Decentralized - Chile, Santiago') -or (Office -eq 'Decentralized - Farmingdale, NY') -or (Office -eq 'Decentralized - Peru, Lima') -or (Office -eq 'Decentralized - Philadelphia') -or (Office -eq 'Decentralized - San Antonio') -or (Office -eq 'Decentralized - San Diego') -or (Office -eq 'Decentralized - Sugar Land') -or (Office -eq 'Decentralized - San Francisco') -or (Office -like 'Decentralized - US,*') -or (Office -like 'Decentralized - Chile, Santiago') -or (Office -like 'Decentralized - Chile, Santiago') -and (-not(Office -like ‘Decentralized - Brazil, Sao Paulo’)) -and (-not(Office -like ‘Decentralized - Colombia, Bogota’)) -and (-not(Office -like ‘Decentralized - Peru, Lima’)) -and (-not(Office -like ‘Decentralized - Mexico, Mexico City’)) -and (-not(Office -like ‘Decentralized - Argentina, Buenos Aires’)) -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’)) –and (-not(RecipientTypeDetailsValue -eq ‘AuditLogMailbox’)) -and (-not(RecipientTypeDetailsValue -eq ‘AuxAuditLogMailbox’)) -and (-not(RecipientTypeDetailsValue –eq ‘SupervisoryReviewPolicyMailbox’)))
Exchange | Exchange Server | Management
{count} votes

Accepted answer
  1. KyleXu-MSFT 26,396 Reputation points
    2021-06-10T02:08:51.227+00:00

    @Austin Sundar

    There missing “()” in your command, the filter before and after "-and" should be independent, you need contain all "-or" in a "()", because they are continuously:

    New-DynamicDistributionGroup -Name DDL2 -Alias DDL2 -RecipientFilter “(RecipientType -eq 'UserMailbox') -and ((Office -eq 'Decentralized - Chile, Santiago') -or (Office -eq 'Decentralized - Farmingdale, NY'))”  
    

    103957-qa-kyle-09-54-15.png

    As AndyDavid said, you don't need to add the red part below into your command, they are added automatically:
    103984-qa-kyle-09-52-58.png

    Here is the result of this command, it doesn't contain the "Bogota":
    103975-qa-kyle-10-07-27.png

    If you cannot see screenshots clearly, you can right click on it and choose "Open image in new tab"


    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


2 additional answers

Sort by: Most helpful
  1. Andy David - MVP 157.5K Reputation points MVP Volunteer Moderator
    2021-06-09T11:58:45.69+00:00

    Its not supported to Add-PSSnapin Microsoft.Exchange.Management.PowerShell.SnapIn

    After you open the remote powershell session on the Exchange Server, you typically simply need to run something like:

    https://learn.microsoft.com/en-us/powershell/module/exchange/new-dynamicdistributiongroup?view=exchange-ps

    New-DynamicDistributionGroup -Name "Marketing Group" -IncludedRecipients "MailboxUsers,MailContacts" -ConditionalDepartment "Marketing","Sales"  
    

    Not sure why you are running all that above


  2. Andy David - MVP 157.5K Reputation points MVP Volunteer Moderator
    2021-06-09T12:27:42.997+00:00

    Simplify it:

    Example

    New-DynamicDistributionGroup -Name "Group" -RecipientFilter "(RecipientType -eq 'UserMailbox') -and (Office -eq 'Decentralized - Chile, Santiago')" 
    

    etc...

    Start from there and add the other offices to the filter.

    Don't add all that other stuff. It will be added automatically.

    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’)) –and (-not(RecipientTypeDetailsValue -eq ‘AuditLogMailbox’)) -and (-not(RecipientTypeDetailsValue -eq ‘AuxAuditLogMailbox’)) -and (-not(RecipientTypeDetailsValue –eq ‘SupervisoryReviewPolicyMailbox’)))

    Stick to the actual filters for the malboxes themselves.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.