Get SamAccountName from csv containing firstname and surname

Hi,

I have been given a csv file containing users Surname and GivenName. Is it possible for PowerShell to read the information contained in this csv and get the SAMAccount Name? Is this possible?
example.png
LVL 1
MattyS82Asked:
Who is Participating?
 
footechCommented:
Do you mean retrieving the information from Active Directory, or generating it from some combination of the info?

If from AD...
Import-Module ActiveDirectory
Import-CSV file.csv | ForEach `
{
    $first = $_.GivenName
    $last = $_.Surname
    Get-ADUser -filter {GivenName -eq $first -and sn -eq $last} |
     Select samAccountName
}

Open in new window

0
 
MattyS82Author Commented:
This is fantastic, thank you.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.