Exchange 2010 Dynamic Groups Recipient Filter format

I am trying to create a custom recipient filter to create dynamic distribution groups.

New-DynamicDistributionGroup -Name “TestGroup" -OrganizationalUnit " Groups" -RecipientContainer "” -RecipientFilter {(RecipientType -eq ‘UserMailbox’ -and Office -eq "Location1”) -and (-not(Department –eq ‘Contractors’))}

1. Its not clear when to use 'location1' or "location1" Appreciate any clarification on that
2. the above syntax is incorrect. I can use the above to create a group for that location, but i want to be able to exclude users with a specific department field. Its too unwieldy to include 99 of 100 departments, i prefer to just filter out the ones i dont want.
3. how to i have multiple departments excluded

Many thanks
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Amit KumarCommented:

You are creating DDL for those are based on location1 and recipient type is user mailbox, if you don't want them to filter location wise then remove -and Office -eq "Location1” syntax. To filter multiple departments use or condition as below mentioned.

New-DynamicDistributionGroup -Name “TestGroup" -OrganizationalUnit " Groups" -RecipientContainer "” -RecipientFilter {(RecipientType -eq ‘UserMailbox’ -and Office -eq "Location1”) -and (-not(Department –eq ‘Contractors’ -or Department –eq ‘Contractors1’))}
mbsadmin1Author Commented:
Thank you. But when i run it get a syntax error. Is something wrong with the way the command is structured?
Amit KumarCommented:
please paste the error
Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

mbsadmin1Author Commented:
Invoke-Command : Cannot bind parameter 'RecipientFilter' to the target. Exception setting "RecipientFilter": "Invalid filter syntax. For a description of the filter parameter syntax see the command help.
"(RecipientType -eq ‘UserMailbox’ -and Office -eq “TestGroup”) -and (-not(Department –eq ‘Contractors’ -or Department –eq
 ‘Contractors1’))" at position 20."
At C:\Users\auser\AppData\Roaming\Microsoft\Exchange\RemotePowerShell\\exchange-server char:29
+             $scriptCmd = { & <<<<  $script:InvokeCommand `
    + CategoryInfo          : WriteError: (:) [New-DynamicDistributionGroup], ParameterBindingException
    + FullyQualifiedErrorId : ParameterBindingFailed,Microsoft.Exchange.Management.RecipientTasks.NewDynamicDistributionGroup
mbsadmin1Author Commented:
thanks, any other thoughts on why this command doesn't work?
Amit KumarCommented:
Remove Office from recipient type:

New-DynamicDistributionGroup -Name “TestGroup" -OrganizationalUnit " Groups" -RecipientContainer "” -RecipientFilter {(RecipientType -eq ‘UserMailbox’) -and (-not(Department –eq ‘Contractors’ -or Department –eq ‘Contractors1’))}

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mbsadmin1Author Commented:
Thanks very much - apologies for late response, but this was really appreciated.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.