'Powershell-EXO - Error with RecipientFilter operator -contains when attempting to set new filters in Dynamic Distro list

Connected to EXO via Powershell

Attempted script:

Set-DynamicDistributionGroup -Identity "Colorado" -RecipientFilter "(((((RecipientTypeDetails -eq 'UserMailbox') -and (CountryOrRegion -eq 'United States')) -and (StateOrProvince -eq 'Co')) -or (CustomAttribute3 -eq 'Colorado')) -and (-not(Department -eq 'Contractor')) -and (-not(Department -contains '-R')) -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')))"

Error: "Cannot bind parameter 'RecipientFilter' to the target. Exception setting "RecipientFilter": ""-contains" is not a valid operator."

the "-R" tag is how we are differing Remote employees vs onsite

Can I not use -contains in this manner?

Edit: For clarity:

If person A is in Dept: "Marketing", and person B is in Dept: "Marketing -R"

I want to exclude person B from the list.

I would use Custom Attributes instead but I have over 500 users and I'd have to do them 1 at a time :(



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source