Solved

Powershell Script to get Samaccountname from list of Email Addresses in CSV file.

Posted on 2016-08-04
3
369 Views
Last Modified: 2016-08-04
HI Experts,

I have a CSV file of about 100 email addresses.  

1- I need to get the samaccountname (logon ID) from each of these email addresses in the file.  

2 - Than add these samaccountnames (logon ID) to a AD distribution group.

Is there a nice powershell script that can accomplish this?  

Thanks
0
Comment
Question by:MSG Boston
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 16

Accepted Solution

by:
FOX earned 500 total points
ID: 41743134
Import-csv "c:\filelocation\file.csv" | ForEach {

        Get-ADUser -Filter "emailaddress -eq '$_'" | Select SamAccountName | Add-ADGroupMember
-Identity Groupname -Member $_.SamAccoutname

}
1
 

Author Closing Comment

by:MSG Boston
ID: 41743197
Thanks, this works FoxLuv

Simple and to the point.
0
 
LVL 16

Expert Comment

by:FOX
ID: 41743202
:)
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A list of top three free exchange EDB viewers that helps the user to extract a mailbox from an unmounted .edb file and get a clear preview of all emails & other items with just a single click on mailboxes.
Previously, on our Nano Server Deployment series, we've created a new nano server image and deployed it on a physical server in part 2. Now we will go through configuration.
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

763 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