I thought i could query the array like this, and it should jsut return "John". What I am getting inside my script when I query $existinguserdetails, is just the first line returned, the "DistinguishedName" value only. Literally if I do a "write-host $existinguserdetails", I get one line only. Even though when I manually run the commands it returns the 13 lines.
by DonJ at 2013-02-28 13:59:52
So... that's because you created an array. You have to tell it which array element you want. Since there's likely only one, $existinguserdetails.surname should work.
One doesn't "query" an array. You just access data in it. Querying implies it's going to search something for you, and it ain't.
Curious: Why are you casting it as an array? Get-ADUser will return a single object if there's only one match, and return a collection (array) if there's more than one match. Do you need to force it into an array?