[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2968
  • Last Modified:

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
}
0
ipsec600
Asked:
ipsec600
1 Solution
 
Joshua GrantomSenior EngineerCommented:
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
 
ipsec600Author Commented:
Thank you Joshua G,

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

Thank you for your support.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now