PowerShell for Windows Admins

Feb 22 2012   1:13PM GMT

object vs value

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

An interesting question came up recently. A Powershell user was trying to access an AD attribute so they did something like this

$x = Get-ADUser -Identity usera -Properties * | select useraccountcontrol


When they tried to use $x it didn’t correctly in the rest of the script.


Select-object is used to filter down the attributes that are left on the object as it passes on the pipeline


PS> Get-ADUser -Identity usera -Properties * | select useraccountcontrol



If you just want the value rather than an object (I know that its still an object but in reality we work directly with the value) then use –expandproperty. On a property with a single value it returns that value

PS> Get-ADUser -Identity usera -Properties * | select -expandproperty useraccountcontrol

 Comment on this Post

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

Share this item with your network: