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
Solved

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

Posted on 2016-08-04
3
291 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
  • 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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

Last week, our Skyport webinar on “How to secure your Active Directory” (https://www.experts-exchange.com/videos/5810/Webinar-Is-Your-Active-Directory-as-Secure-as-You-Think.html?cid=Gene_Skyport) provided 218 attendees with a step-by-step guide for…
Windows 10 came with  a lot of built in applications, Some organisations leave them there, some will control them using GPO's. This Article is useful for those who do not want to have any applications in their image (example:me).
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 from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

839 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