0

I need to export some information from active directory. The current powershell script successfully get all the information it is asking for, but I want to also grab the user attribute "description" or "company."

$OUpath = 'OU=OU,DC=DC'
$ExportPath = 'C:\path\users_in_ou7.csv'
Get-ADUser -Filter * -SearchBase $OUpath | Select-object GivenName, Surname,Name,UserPrincipalName | Export-Csv -NoType $ExportPath

When I add either of those to the Select-object portion is turns up blank in my CSV. For example:

Select-object Description, Company, GivenName, Surname, Name, UserPrincipalName

Column headers are inserted into the CSV, but the values are blank. These attributes are populated in each of the user properties in AD. I am not sure if I am calling them correctly in my script. Any help would be appreiceiated. Thank you.

2 Answers 2

2

Use the -Properties parameter of the Get-ADUser cmdlet.

From the Get-ADUser documentation:

This cmdlet retrieves a default set of user object properties. To retrieve additional properties use the Properties parameter.

Specify properties for this parameter as a comma-separated list of names. To display all of the attributes that are set on the object, specify * (asterisk).

0

You add the -properties * to the query to extract all attributes.

Get-ADUser -Filter * -SearchBase $OUpath -properties * | Select-object Description,GivenName, Surname,Name,UserPrincipalName | Export-Csv -NoType $ExportPath

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.