# Email to SamAccountname output

**URL:** <https://forums.powershell.org/t/email-to-samaccountname-output/20731>\
**Category:** PowerShell Help\
**Created:** [October 25, 2022, 6:40am UTC](https://forums.powershell.org/t/email-to-samaccountname-output/20731 "2022-10-25T06:40:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pba1211](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/pba1211/32/1421_2.png) [@pba1211](https://forums.powershell.org/u/pba1211)\
**Post date:** [October 25, 2022, 6:40am UTC](https://forums.powershell.org/t/email-to-samaccountname-output/20731/1 "2022-10-25T06:40:18Z")

</div>

Hello,

Several times i need to get the Samaccountname , by using the emailaddress of a user.

The thing is that I do get the Samaccountname, only when I send the output to the clipboard  
the output tells me that is is a Samaccountname  
“@{samaccountname= accountname}” ( lucky me, that is what I need…🙂 )

Only…I am looking for the way to send it to the clipboard without the @{samaccountname= accountname} Just the “Samaccountname”

Thank you in advance for the suggestions,

MY CSV:  
UserID Mail Naam  
User1 [user1@powershel.org](mailto:user1@powershel.org) User. one

```auto

$maillist = Import-Csv P:\Users\PieterB\Scripts\CSV\input.csv -Delimiter ";"

$Sam = foreach( $address in $maillist.mail){
     get-aduser -server domainname -filter "emailaddress -eq '$($address)'" -Properties * |select samaccountname
     }
     
  $maillist.count
  $Sam.count

  $sam |Set-Clipboard

```

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [October 25, 2022, 7:08am UTC](https://forums.powershell.org/t/email-to-samaccountname-output/20731/2 "2022-10-25T07:08:08Z")

</div>

`$sam` is still an object. If you only need the pure strings you have to either use `Select-Object -ExpandProperty` inside your loop to catch only the content of the property `sAMAccountName` or you use `$sam.sAMAccountName` instead of `$sam` for the output. This way you access the property `sAMAccountName` of the object saved in the variable `$sam`. 😉 👍🏽

---

<div class="post-metadata">

**Author:** ![pba1211](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/pba1211/32/1421_2.png) [@pba1211](https://forums.powershell.org/u/pba1211)\
**Post date:** [October 26, 2022, 5:52am UTC](https://forums.powershell.org/t/email-to-samaccountname-output/20731/3 "2022-10-26T05:52:42Z")

</div>

My oh My… I was that focussed on the loop and to get it work, that I overlooked the header indeed. 😊

Thanks for pointing out in the right direction, cu in my next post . 😂

👋

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:16pm UTC](https://forums.powershell.org/t/email-to-samaccountname-output/20731/4 "2024-05-16T20:16:26Z")

</div>


