Add Users to a Group based on Email Address

ipsec600
ipsec600 used Ask the Experts™
on
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
}
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Joshua GrantomSenior Systems Administrator
Top Expert 2014

Commented:
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

Top Expert 2014
Commented:
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

Author

Commented:
Thank you Joshua G,

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

Thank you for your support.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial