How do I export ONE attribute from AD?

I need to extract one attribute from certain user accounts in Active Directory, how do I do this? Â I tried using the “Get-ADUser <username> -properties <attribute name>”, but it gives me all the basic attributes of the the user, not just the one attribute I want. Â So, say for example, I want to get the ‘cn’ of user JohnHDoe. Â I only want it to return ‘John’ and not all the other stuff. Â Thanks.

Get-ADUser <username> Â | Select -Prop cn

Get-ADUser always returns a base set of properties. The -Properties parameter specifies additional ones to retrieve. Select-Object specifies any properties of the input object that you want included in the output, if you want something less than the default of “everything.”

So how would I use the ‘Select-object’ cmdlet to get one attribute from a specific AD user account? Â I looked at examples, and I didn’t see a way to select a specific user account. Â I would want to get the ‘cn’ from the ‘JohnHDoe’ AD user account, for example. Â Maybe a “Where {$._<username> }” statement?

PowerShell works by default with objects, which have (at least) properties, and are not simple strings like you have in UNIX variants. Even simple strings in PowerShell are objects. But, you can format an object to output it for human consumption in a way that looks like a simple string. As Don said, Select-Object is one of those tools. So, I think that what you want to do is best performed by using the -ExpandProperty switch with Select-Object. This will output just a plain “John” for you:

Get-ADUser "JohnHDoe" | Select-ExpandProperty CN