[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1444
  • Last Modified:

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

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
MSG Boston
Asked:
MSG Boston
  • 2
1 Solution
 
FOXActive Directory/Exchange EngineerCommented:
Import-csv "c:\filelocation\file.csv" | ForEach {

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

}
1
 
MSG BostonAuthor Commented:
Thanks, this works FoxLuv

Simple and to the point.
0
 
FOXActive Directory/Exchange EngineerCommented:
:)
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now