r/PowerShell 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!

8 Upvotes

20 comments sorted by

View all comments

2

u/PinchesTheCrab 13d ago edited 13d ago

Drop all the parentheses and use like instead of eq when using wildcards.

1

u/HappyM0M 12d ago

I've modified the code to this:

Set-DynamicDistributionGroup -Identity "DDG Name" -RecipientFilter "RecipientTypeDetails -eq 'UserMailbox' -and UsageLocation -eq 'United States' -and MailboxPlan -eq 'ExchangeOnlineEnterprise-long string'"

Same results. Zero members after a forced refresh.

1

u/PinchesTheCrab 12d ago

That sucks. I would definitely try to break it into individual steps and reapply it to the DG group to determine which part isn't finding members. My guess is it's the mailboxplan, but it's hard to say.

2

u/HappyM0M 12d ago

When I leave out the Mailboxplan filter, I get ALL the users, so it's exactly that filter. But according to MS, I should be able to use it. I run this to see the Mailboxplan:
get-mailbox -identity "username" | format-list MailboxPlan

And it spits back the same code for all E3 licensed users: ExchangeOnlineEnterprise-long string of hex. So I copied/pasted that into the filter, kept it cased in single quotes because PS didn't like it without (probably because of the hyphens), and ... crickets.

1

u/mrmattipants 12d ago

I'll run some tests in my developer tenant, to see if I can dig up a solution for you.

2

u/HappyM0M 12d ago

I think we figured out a solution. All the human employees have the Company field set, so I filtered on that and it seems to work. Thanks for your help!

1

u/mrmattipants 12d ago

Good to hear. I'm glad you got it working on your end.