Email to SamAccountname output

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…:slight_smile: )

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 User. one


$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

$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. :wink: :+1:t4:

1 Like

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

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

:wave: