AntiMalware Status

Export users SamAccountName from Email address csv file

Quick PowerShell script to accomplish a task to get a list of users by SamAccountName from provided csv file with email addresses.

The csv file has one column “email’ under which as email addresses that I need to import in PowerShell for query and output SamAccountName for the users into txt file.

Put the csv file with emails in the same directory where is your PowerShell and you can run the script to export the SamAccountName for the users.

1
2
Get-Content C:\Scripts\email.csv | ForEach-Object {
Get-ADUser -Filter {EmailAddress -eq $_} -Properties DistinguishedName,Name,DisplayName,EmailAddress | Select-Object SamAccountName,EmailAddress} | Export-CSV -Path C:\User_list.csv -NoTypeInformation

Use and modify as you need 🙂

Leave a Reply