Forum Discussion
JoshuaLance
Aug 07, 2024Copper Contributor
List users not in distribution lists
I am looking for a way to list all users that are not in 8 specific distribution lists. I have found an option that gets close but it is not correct. I only want to display the users that are not i...
VasilMichev
Aug 08, 2024MVP
The correct way of doing this will be with a server-side filter and the MemberOfGroup property. Unfortunately, it only works against the DN of the group, so you need to fetch those first. Here's an example:
Get-Mailbox -Filter "MemberOfGroup -ne 'CN=DG1,OU=tenant.onmicrosoft.com,OU=Microsoft Exchange Hosted Organizations,DC=EURPR03A001,DC=prod,DC=outlook,DC=com' -and MemberOfGroup -ne 'CN=DG2,OU=tenant.onmicrosoft.com,OU=Microsoft Exchange Hosted Organizations,DC=EURPR03A001,DC=prod,DC=outlook,DC=com'"
The example is just for 2 DGs, add similar entries for the rest.
Get-Mailbox -Filter "MemberOfGroup -ne 'CN=DG1,OU=tenant.onmicrosoft.com,OU=Microsoft Exchange Hosted Organizations,DC=EURPR03A001,DC=prod,DC=outlook,DC=com' -and MemberOfGroup -ne 'CN=DG2,OU=tenant.onmicrosoft.com,OU=Microsoft Exchange Hosted Organizations,DC=EURPR03A001,DC=prod,DC=outlook,DC=com'"
The example is just for 2 DGs, add similar entries for the rest.
- JoshuaLanceAug 13, 2024Copper ContributorThanks for the response.
I will give this a try and let you know how it goes.