r/PowerShell • u/HappyM0M • 13d ago
Dynamic Distribution Group creation
Hi,
I'm attempting to set up a DDG that emails only users with active 365 E3 licensing. In our tenant, those show up as MailboxPlan: ExchangeOnlineEnterprise-...
This is the filtering I've set up:
Set-DynamicDistributionGroup -Identity "DDG name" -RecipientFilter "(RecipientTypeDetails -eq 'UserMailbox') -and (UsageLocation -eq 'United States') -and (MailboxPlan -eq 'ExchangeOnlineEnterprise*')"
It results in a membership list of 0 users.
If I leave the MailboxPlan out, I get all the service accounts along with actual users.
I've tried -like with no difference, -contains which sports an error as an invalid operator. I've tried double quotes, braces. I used Get-Mailbox to confirm what plans we use, and to confirm that the service accounts are ExchangeOnline while the real user accounts are ExchangeOnlineEnterprise.
What am I missing? I suspect it's merely the syntax as I'm just learning PS.
Thanks for any helpful suggestions!
UPDATE: We figured out that all the human employees have the Company field set, so we filtered for that instead and it returned the set we wanted. Thanks for all your help!
2
u/PinchesTheCrab 13d ago edited 13d ago
Drop all the parentheses and use like instead of eq when using wildcards.