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?
Who is Participating?

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

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.

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:

The example is a mix, I presume
Here is a set of available cmdlets for exchange 2010.

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
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}
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){$}

Hope this will be helpful for you.
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?
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? and 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.
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

From novice to tech pro — start learning today.