Exchange 2010 - show users NOT in a distribution list

Is there some way, with PowerShell or otherwise, to get a list of all users who are NOT in a particular distribution list?  I have a distribution list of users who are not allowed to send/receive external email.  I would like a list of all the users/email addresses that are NOT in that list (ie. those that can send/receive external email).  Is there a way to do that in Exchange 2010?

Who is Participating?

Run this command from AD (Command Prompt). TO pull the exact  attribute of the Distribution group, go to ADUC > right click the distribution group > Properties > Attribute Editor > Distinguished Name > Copy and Paste it ahead of !memberof=cn parameter.

DSQuery * -Filter "(&(objectCategory=user)(!memberOf=CN=xxxxx,OU=xxxx,OU=xxxx,DC=xxx,DC=xx,DC=xx))" -Attr samAccountName -Limit 0
Or the Powershell way (with Quest free cmdlets).
get-QADUser -SearchRoot 'DC=My,DC=Company,DC=local' -NotMemberOf 'DOMAIN\NoSoup4You'

Or to check for nested members... SLOWER.
get-QADUser -SearchRoot 'DC=My,DC=Company,DC=local' -NotIndirectMemberOf 'DOMAIN\Group'

bruno71Author Commented:
Thanks paritoshjani.  That worked.  I tweaked it a little to give me the email address and then exported it to a text file.

DSQuery * -Filter "(&(objectCategory=user)(!memberOf=CN=xxxxx,OU=xxxx,OU=xxxx,DC=xxx,DC=xx,DC=xx))" -Attr mail -Limit 0 > c:\textfile.txt

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.