Forum Discussion

AllanKelly's avatar
AllanKelly
Copper Contributor
Oct 25, 2022

Excluding users from Dynamic Distribution Group who are not members of M365 Security Group

Hi all,

 

I'm trying to narrow the scope of our existing company-wide dynamic distribution list to only licensed users. I want to accomplish this by requiring members of the dynamic distribution list to be members of a particular M365 security group. I'm not sure how to accomplish this in PS and would appreciate any assistance.

  • "Pure" security groups are not valid Exchange recipients, so you cannot use them in filters and such. A mail-enabled security group would work. Here's how a sample filter can look like:

    Get-Recipient -RecipientPreviewFilter {MemberOfGroup -eq "CN=MESG,OU=tenant.onmicrosoft.com,OU=Microsoft Exchange Hosted Organizations,DC=EURPR03A001,DC=prod,DC=outlook,DC=com"}

    where you need to provide the DistinguishedName value for the group.

Resources