How can I get a list of Exchange Contacts not in any distribution groups?

I am trying to pull a list of all the email contacts in our Exchange 2010 environment that are not a member of any group. I want to find contacts not in the groups so I can eventually remove them from our system.

Any suggestions on how to accomplish this in Powershell or with a script?
itregosaAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

arnoldCommented:
The technet link below includes an example using powershell to see all the distribution groups a user belongs to.

Your inquiry will be to nest two one listing all contacts, and then comparing whether they are:

https://social.technet.microsoft.com/forums/exchange/en-US/08bb68fd-5116-427c-869b-3f8686d5d904/list-of-all-distribution-lists-that-one-user-is-a-member-of-powershell

The example is a mix, I presume
Here is a set of available cmdlets for exchange 2010.
https://technet.microsoft.com/en-us/library/bb124413%28v=exchg.141%29.aspx
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
LeoCommented:
Try this.....
foreach ($group in Get-DistributionGroup) { get-distributiongroupmember $group | sort displayname | ft @{expression={$_.displayname};Label=”$group”} | Out-File c:\temp\DistributionListMembers.txt -append}

This will generate better output.

foreach ($group in Get-DistributionGroup | sort displayname) { get-distributiongroupmember $group | sort displayname | ft @{expression={$_.displayname};Label=”$group”} | Out-File c:\temp\DistributionListMembers.txt -append}
0
Minecraft_ EndermanCommented:
I have a script that will tell you what distribution groups a user is a member of.

$User = read-host -Prompt "Enter Username"
$user_dn = (get-mailbox $user).distinguishedname
"User " + $User + " is a member of the following groups:"
foreach ($group in get-distributiongroup -resultsize unlimited){
if ((get-distributiongroupmember $group.identity | select -expand distinguishedname) -contains $user_dn){$group.name}
}

Hope this will be helpful for you.
0
itregosaAuthor Commented:
Thanks everyone, but these aren't quite what I'm looking for. Instead of listing all of the members of the groups, I'm trying to list all the contacts without groups. Or if it is easier, all the contacts and their groups they are a member of. Any thoughts?
0
arnoldCommented:
The examples provided do just that.
You list the recipients you have (first Loop)
Then you look for which groups they belong to (inner loop)

one example is prompting you for the user whose information you are interested in and then it lists which groups this account is a member of.

Do you have recipients who also have aliases?
regosa@yourdomain.com and itregosa@yourdomain.com end up in your mailbox? One account is the primary email address, while the other is an alias, secondary, tertiary ........

The other examples deal with listing all the distribution groups and their members.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Exchange

From novice to tech pro — start learning today.