?
Solved

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

Posted on 2016-08-04
3
Medium Priority
?
989 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 2000 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

This article lists the top 5 free OST to PST Converter Tools. These tools save a lot of time for users when they want to convert OST to PST after their exchange server is no longer available or some other critical issue with exchange server or impor…
Wouldn't it be nice if objects in Active Directory automatically moved into the correct Organizational Units? This is what AutoAD aims to do and as a plus, it automatically creates Sites, Subnets, and Organizational Units.
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Suggested Courses

649 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