1

I am trying to search for individual properties of an AD-User, when I run

(Get-ADUser $userName).$targetProperty

I get nothing When I run

Get-ADUser $userName | select $targetProperty

I get the property and a blank underneath. BUT when I run.

Get-ADUser $user -Properties * 

I get the full list & when I look at $targetProperty, there is a value already there. My environment is 1 DC, its local, and I am in Admin mode.

2 Answers 2

0

It depends on the target property you are trying to get. If it is not one of the properties in the default set (the ones you get when you just run Get-ADUser testuser), it isn't in the result set, so you can't get to it elsewhere in your command.

Here are the default properties.

DistinguishedName : CN=Test User,CN=Users,DC=domain,DC=local
Enabled           : True
GivenName         : Test
Name              : Test User
ObjectClass       : user
ObjectGUID        : 94916bd1-008e-409f-a1b3-eaXXXXXX266e
SamAccountName    : TestUser
SID               : S-1-5-21-23XXXXXX88-41XXXXX83-1941XXXX34-32584
Surname           : User
UserPrincipalName : [email protected]

Let's say the property you want is Title. So your first command is this:

(Get-ADUser testuser).Title

Title is not in the default set of properties, so the part in parentheses doesn't include a Title property, so the result of the combined command is nothing.

Second attempt:

Get-ADUser testuser | select Title

That gives you the word "Title" as the header of the column, but there is still no value for it, because the first part of the command still doesn't include a Title property in the results.

Third attempt:

Get-ADUser testuser -Properties * 

Aha! That's getting close. It includes the Title property, along with a whole bunch of others that you don't care about right now.

Fourth attempt:

(Get-ADUser testuser -Properties *).title

That's it! This combination gets all of the properties of the user (so that includes Title) and then only shows you the Title property.

Optional: You can make it a bit faster by not bothering to ask for the 100+ properties that -Properties * gives you, and only get the default properties plus Title, with this:

(Get-ADUser testuser -Properties Title).Title
0

I found that the following lets me get the info, but why was it not working with my other commands?

(Get-ADUser $user -Properties *).$targetProperty
1
  • Probably because you're pulling all properties, then grabbing one property out of all of them. That's why using piping to select $targetproperty works.
    – Davidw
    Commented Jul 23, 2019 at 16:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .