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



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 |





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.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s