Add Users to a Group based on Email Address

Hi Experts,

I need to update group membership for 1000 users for a single group, I have received email address for those users.

Would you kindly advise what Power Shell command would be to perform the task.

So far I have found the followings

http://gallery.technet.microsoft.com/scriptcenter/ffff189d-8ef1-4903-b19c-12dcd352c88e

But I need to update group membership  based on email address. At the same time, those membership will not update can I get any log output so that I can manually add them. Could you please advise.

Import-module ActiveDirectory
Import-CSV "C:\Scripts\Users.csv" | % {
Add-ADGroupMember -Identity TestGroup1 -Member $_.UserName
}
ipsec600Asked:
Who is Participating?
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.

Joshua GrantomSenior Systems AdministratorCommented:
First run this from exchange management shell to convert your CSV to a CSV with all of their usernames

$users = Import-Csv <csv file>
$outUsers = @()
Foreach ($user in $users)
{
$outUsers += Get-Mailbox $user | Select-Object samaccountname
}
$outUsers |Export-Csv <out csv file> -NoTypeInformation

Open in new window


Then you can run this script with the new csv file.

Import-module ActiveDirectory
Import-CSV "C:\Scripts\Users.csv" | % {
Add-ADGroupMember -Identity TestGroup1 -Member $_.UserName
} 

Open in new window

0
footechCommented:
If you just have a list of email addresses in a file, the below should work.  Import the AD module if needed.
Get-Content users.txt | ForEach `
{
    Get-ADUser -Filter {mail -eq $_} | ForEach `
    { Add-ADGroupMember -Identity RDS-VPN -Member $_.samaccountname }
}

Open in new window

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
ipsec600Author Commented:
Thank you Joshua G,

I tried with the script of footech, it works perfectly.

Thank you for your support.
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
Powershell

From novice to tech pro — start learning today.

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.