Link to home
Start Free TrialLog in
Avatar of ipsec600
ipsec600

asked on

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
}
Avatar of Joshua Grantom
Joshua Grantom
Flag of United States of America image

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

ASKER CERTIFIED SOLUTION
Avatar of footech
footech
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ipsec600
ipsec600

ASKER

Thank you Joshua G,

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

Thank you for your support.