We help IT Professionals succeed at work.

Add Users to a Group based on Email Address

4,341 Views
Last Modified: 2014-08-10
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

Joshua GrantomSystems Administrator
CERTIFIED EXPERT
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

CERTIFIED EXPERT
Top Expert 2014
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION

Author

Commented:
Thank you Joshua G,

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

Thank you for your support.