Add Users to a Group based on Email Address

Posted on 2014-08-06
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

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
Question by:ipsec600
    LVL 16

    Expert Comment

    by:Joshua Grantom
    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

    LVL 38

    Accepted Solution

    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 Comment

    Thank you Joshua G,

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

    Thank you for your support.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Suggested Solutions

    This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now