Powershell script to import csv and to export file with samaccountname

Powershell import a csv file that already has first name, last name, and email address and need to add another column for samaccountname.
CiscoAznAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CiscoAznAuthor Commented:
Receiving errors. You don't have a closing bracket and it's also giving me Cannot convert the "-properties" value of type.
0
Timothy McCartneySYS ADMINISTR I INFRASCommented:
Do you just need an additional column added with no actual data?

For example... You feed the script a csv file with the headers you've mentioned, and then it outputs an identical csv file with an additional, empty samaccountname field?

Or... Are you wanting to capture the samaccountname data as a part of the script and export all the data into a new csv file? Your question is a tad unclear on what you're trying to accomplish.
0
CiscoAznAuthor Commented:
Yes that's correct export out with another column that include the samaccountname. sorry for the confusion.
0
Shaun VermaakTechnical Specialist/DeveloperCommented:
Post your script
0
Gopi RajuSystem AnalystCommented:
You can use the below script to get the SAM account name. UserName in the script should match the header of the column in your input csv file.

import-module ActiveDirectory

Import-CSV C:\filename.csv | Foreach-Object{

get-aduser -Identity $_.UserName | Select Name, SamAccountName

} | export-csv C:\outputfile.csv -Notypeinformation
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.