ethan davis
ethan davis

Reputation: 35

Powershell Active Directory script to export csv with specific information/attributes

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.

Upvotes: 0

Views: 2293

Answers (2)

Subbammahars
Subbammahars

Reputation: 1

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

Upvotes: 0

Josef Bláha
Josef Bláha

Reputation: 1113

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).

Upvotes: 2

Related Questions