2

So I have a list of Active Directory users:

$users = Get-AdUser -Filter {Enabled -eq "True"}

What I want to do is group them based on their description since you have 3 possible descriptions in the whole user list.

However: I can't even seem to even use the Descriptionfield inside of a foreach:

foreach ($user in $users)
{
    Write-Host $user.Name    
    Write-Host $user.Description
}

Their name shows but not their description.

Why is this?

1 Answer 1

4

Get-ADUser only returns specific properties by default. The description property is not one of these. To ensure it is returned you need to use the following parameter with Get-ADUser:

-Properties Description

"This cmdlet retrieves a default set of user object properties. To retrieve additional properties use the Properties parameter." - https://technet.microsoft.com/en-gb/library/ee617241.aspx

Sign up to request clarification or add additional context in comments.

4 Comments

Thank you very much Mark, can I ask you where to see the default properties of each cmdlet?
I don't think it's well documented, but if you pipe your results to the get-member cmdlet then you will see all the objects properties and methods. For example get-aduser -filter * | get-member
Actually it looks like its documented for get-aduser here: social.technet.microsoft.com/wiki/contents/articles/… . Also FYI you can get all properties returned by doing -properties *.
Thank you very much

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.