locked
Trouble getting the Primary mail address of a list of users RRS feed

  • Question

  • I need to add the Primary mail address to a csv file that is a list of my users. I have tried the code below but I get strange results for the mail address.

    $Users = import-csv aduserstest.csv | Select-Object *,@{Name='EmailAddress';Expression={(get-mailbox $_.samaccountname | Select PrimarySMTPAddress)}} | export-csv i:\employeenumber\FullUser.csv -notype

    what I get back is

    "surname","givenname","samaccountname","employeenumber","enabled","EmailAddress"
    "Hackney","Sue","shackney","100001","TRUE","@{PrimarySmtpAddress=Sue.Hackney@XXX.com}"
    "Taylor","Sheila","STaylor","100005","TRUE","@{PrimarySmtpAddress=Sheila.Taylor@XXX.com}"

    The XXX is masking the domain name.

    The original csv file contains all of the info except for the addrersses.

    Can anyone help me to just get the value of the address?

    Friday, January 13, 2017 7:54 PM

Answers

  • import-csv aduserstest.csv | 
    	Select-Object *, @{ Name = 'EmailAddress'; Expression = { (get-mailbox $_.samaccountname | Select -expand PrimarySMTPAddress) } } | 
    	export-csv i:\employeenumber\FullUser.csv -notype


    \_(ツ)_/

    • Marked as answer by JRussell97 Friday, January 13, 2017 8:54 PM
    Friday, January 13, 2017 8:35 PM

All replies

  • import-csv aduserstest.csv | 
    	Select-Object *, @{ Name = 'EmailAddress'; Expression = { (get-mailbox $_.samaccountname | Select -expand PrimarySMTPAddress) } } | 
    	export-csv i:\employeenumber\FullUser.csv -notype


    \_(ツ)_/

    • Marked as answer by JRussell97 Friday, January 13, 2017 8:54 PM
    Friday, January 13, 2017 8:35 PM
  • That worked beautifully.  Thanks JRV.
    Friday, January 13, 2017 8:55 PM