r/PowerShell • u/dverbern • May 26 '26
Question PowerShell means of tracking whether a given AD user is a member of a distribution list?
Hi All,
We have a hybrid AD on-premises / cloud with Microsoft Entra and Azure and Exchange.
We've got a large number of distribution lists (DLs) for the sending of emails to specific parts of the business. Most of these DLs are themselves members of larger DLs until we have a top-level "All Staff" style DL.
Despite our best efforts, sometimes a mistake will occur and a staff member will fail to receive emails sent to these top-level DLs.
I've been trying to use PowerShell to loop through each of our AD users and check whether they are members of (via inheritance or direct membership) these top-level DLs. I'm using an OID recursive chain rule to do this, of which I'm fairly familiar.
Currently, my script is telling me pretty much no one is missing membership of the DL in question and I don't think its right and the reason I don't think it is correct is because my script logic is looking for membership via any type of inheritance, whereas I'm pretty sure that Exchange needs a user to be a direct member of a DL are some point in the inheritance chain.
For instance, I'm pretty sure that users's can't just inherit membership of a DL via a security group that is nested within the DL, at some point the user must be a direct member of a DL within another DL if that membership is to register for the purposes of sending emails.
Maybe I'm talking rubbish, certainly feels like it.
My question - has anyone encountered an issue like this where you need to follow a potentially-convoluted set of inheritance to see if a user might be a valid recipient of an email sent to a DL?
Makes me wonder if Exchange does some sort of on-the-spot calculation of the full set of recipients and if I can somehow attempt the same logic ....
3
u/purplemonkeymad May 26 '26
Check the tracking logs for that email, you should see a resolve item in the log that will tell you exactly who it resolved the members as. If they are in the list, then it's not a membership issue. Or you can at least use the members there to narrow your scope.
2
u/titlrequired May 26 '26
In these situations I pick someone I definitely know is in the group, via each method, nested/direct, and someone I know definitely is not via any method.
Are you running it against a particular user ie, is this user in this group or any nested group within this group?
Or are you getting all members of all groups and looking for mistakes?
7
u/cartmanOne May 26 '26
If a Distribution List contains a Security Group as a member, that Security Group should be mail-enabled for its members to receive a mail sent to the DL. If a security group isn’t mail enabled, it won’t be seen by Exchange as a Distribution Group and its members won’t be included in the DL expansion. So yes, you could potentially have a situation where a member of a “group” nested within a DL doesn’t receive a mail. Make sure your recursive membership check is scoped to check for members of DLs and mail-enabled security groups only. Or better yet, use the Exchange module to do the checks (Get-DistributionGroup and Get-DistributionGroupMember)
3
u/BadShepherd66 May 26 '26
Pull a list of the top level list with recourse Match users against that
2
u/leblancch May 26 '26
Not sure now but when we had Exchange on orem, there was an exchange powershell module with functions that could help this.
2
u/BlackV May 26 '26
so if you know the distrubtion list, why are noy just getting its members recursively and checking if member? rather than starting with the user?
2
u/techierealtor May 26 '26
Curious why you are trying to reinvent the wheel rather than using dynamic groups in Azure? You could automate a chunk of this fairly quickly and not even need to worry about inheritance.
1
u/UserProv_Minotaur May 26 '26
Are you sure the DLs in AD are being used and it's not a legacy? But IIRC the inheritance of any scoped Distribution group breaks for Security groups added to it. For my org, we check the user's memberships in OWA to see what DLs they are added to there. But a Get-ADGroupMember -recursive on the DL should get you all members of a top-level group through nested groups, or Get-ADPrincipalGroupMembership will tell you what DL the user would be a member of, though neither will really be useful if you're managing the DLs in O365 or through Azure....
1
u/Ferretau May 27 '26
If you are running Exchange Online and not on premises you need to query the groups in Exchange Online - the local AD groups may be different when synced to Entra. Entra/Exchange Online has different rules around groups and as a result some users that are fine in groups in AD may not be in the group in the cloud.
1
u/MyOtherSide1984 May 31 '26
You could also do a mail trace and see why they didn't get it, but yes, the sub-DL's need to be mail enabled without send restrictions or moderation in place (unless desired). Also be aware if sender authentication required is enabled as that could cause some odd issues.
I thought all DL's were mail enabled and then security enabling them just add the security function in a hybrid environment, but perhaps I'm wrong. That's how we set up our DL's so they are all mail enabled, but restricted when need be.