Converting a csv file with a list of email addresses to sam accounts. If someone can assist me I have the csv fil if necessary
Welcome to the forum. We do not write solutions for people but we will provide help on specific questions on code. If you have code you are working on then please post it with the code formatting button ‘</>’
you should probably edit your post and remove your email address.
I didn’t run your code, but from looking at it we just have to assume that your CSV contains at least a column with the header value of “emailaddress”.
You’re focusing on the DisplayName property when you said you were specifically trying to get the SamAccountName property.
What happens when you try $adu.samaccountname
instead?
Firstly, you must have a .csv file that includes staff emails ordered by column. The first line is named “Email.”
$emails= Import-Csv -LiteralPath <your_csv_file_path>
$emails | foreach {get-aduser -Filter "mail -like '$($_.Email)'" -Properties mail | Select-Object mail,samaccountname} | export-csv C:\temp\samAccountname.csv -NoTypeInformation
The out file will include email and samaccountname. You can add more AD user properties to the out file if you want.
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.