Solved

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

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

Join & Write a Comment

This process describes the steps required to Import and Export data from and to .pst files using Exchange 2010. We can use these steps to export data from a user to a .pst file, import data back to the same or a different user, or even import data t…
Following basic email etiquette rules will help you write a professional email and achieve a good, lasting impression with your contacts.
In this video we show how to create a Contact in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Recipients >> Contact ta…
In this video we show how to create a mailbox database in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Servers >> Data…

747 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

13 Experts available now in Live!

Get 1:1 Help Now