# Converting a csv file with a list of email addresses to sam accounts

**URL:** <https://forums.powershell.org/t/converting-a-csv-file-with-a-list-of-email-addresses-to-sam-accounts/24969>\
**Category:** PowerShell Help\
**Created:** [November 6, 2024, 2:29pm UTC](https://forums.powershell.org/t/converting-a-csv-file-with-a-list-of-email-addresses-to-sam-accounts/24969 "2024-11-06T14:29:17Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![cflood1971](https://avatars.discourse-cdn.com/v4/letter/c/7ba0ec/32.png) [@cflood1971](https://forums.powershell.org/u/cflood1971)\
**Post date:** [November 6, 2024, 2:29pm UTC](https://forums.powershell.org/t/converting-a-csv-file-with-a-list-of-email-addresses-to-sam-accounts/24969/1 "2024-11-06T14:29:17Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![neemobeer](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/neemobeer/32/4087_2.png) [@neemobeer](https://forums.powershell.org/u/neemobeer)\
**Post date:** [November 6, 2024, 2:48pm UTC](https://forums.powershell.org/t/converting-a-csv-file-with-a-list-of-email-addresses-to-sam-accounts/24969/2 "2024-11-06T14:48:10Z")

</div>

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 ‘\</\>’

---

<div class="post-metadata">

**Author:** ![grey0ut](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/grey0ut/32/5310_2.png) [@grey0ut](https://forums.powershell.org/u/grey0ut)\
**Post date:** [November 7, 2024, 2:28am UTC](https://forums.powershell.org/t/converting-a-csv-file-with-a-list-of-email-addresses-to-sam-accounts/24969/4 "2024-11-07T02:28:36Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![ambre](https://avatars.discourse-cdn.com/v4/letter/a/b2d939/32.png) [@ambre](https://forums.powershell.org/u/ambre)\
**Post date:** [November 8, 2024, 12:06pm UTC](https://forums.powershell.org/t/converting-a-csv-file-with-a-list-of-email-addresses-to-sam-accounts/24969/5 "2024-11-08T12:06:27Z")

</div>

Firstly, you must have a .csv file that includes staff emails ordered by column. The first line is named “Email.”

```auto
$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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/1X/385e4f9fe133561ad30a814262fe0e0ae6bc3ef0.png) [@system](https://forums.powershell.org/u/system)\
**Post date:** [December 8, 2024, 12:06pm UTC](https://forums.powershell.org/t/converting-a-csv-file-with-a-list-of-email-addresses-to-sam-accounts/24969/6 "2024-12-08T12:06:34Z")

</div>

Closed on December 8, 2024, 12:06pm UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
