itregosa
asked on
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?
Any suggestions on how to accomplish this in Powershell or with a script?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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-distributiongroupmem ber $group.identity | select -expand distinguishedname) -contains $user_dn){$group.name}
}
Hope this will be helpful for you.
$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-distributiongroupmem
}
Hope this will be helpful for you.
ASKER
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?
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.
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.
foreach ($group in Get-DistributionGroup) { get-distributiongroupmembe
This will generate better output.
foreach ($group in Get-DistributionGroup | sort displayname) { get-distributiongroupmembe