PowerShell: Get-ADuser and looping through attributes

I have got to blog about this. Here is what I was doing, I wanted to get the mail and employeeid information for some users, so I put this in my PS script

$user1=get-aduser jdoe1 -properties mail,employeeid | select mail,employeeid

$user1mail=$user1.mail

$user1employeeid=$user1.employeeid

When I do this from a PS command prompt, it works fine and returns the employeeid. if I put this in a PSscript, I get nothing for empoyeeid but I get a value for mail. After much back and forth, I had to do this

$user1=get-aduser jdoe1 -properties mail,employeeid | select mail,employeeid |

ForEach-Object{

$user1mail=$_.mail

$user1employeeid=$_.employeeid

}

Still stunning to me why I have to go through this gyration in the PS script to get my employeeid info. Does it mean if I use get-aduser with mutiple attributes, I must pipe the results to somewhere in order to iterate through the results? I didn’t see any blog specifically on this so decided to blog it especially for my own records.