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.
Best Answer
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.
Let's say the property you want is
Title
. So your first command is this:Title
is not in the default set of properties, so the part in parentheses doesn't include aTitle
property, so the result of the combined command is nothing.Second attempt:
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:
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:
That's it! This combination gets all of the properties of the user (so that includes
Title
) and then only shows you theTitle
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 plusTitle
, with this: