Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I am trying to export a list of some user information from Active Directory 2003 using Powershell.

So far, I'm able to display the specific list of properties using something like this:

if ( (Get-PSSnapin -Name Quest.ActiveRoles.ADManagement -ErrorAction SilentlyContinue) -eq $null )
{
    Add-PsSnapin Quest.ActiveRoles.ADManagement
}

get-qaduser -company "Company","Consultant" `
    -enabled -DontUseDefaultIncludedProperties -IncludedProperties 'givenName','sn','telephoneNumber','mail','company' `
    | sort-object `
    | format-table givenname,sn,company,telephonenumber,mail `

However, if I try to pipe the output to export-csv, instead of format-table, I get all the properties of each domain object.

If I do something like the following:

    | format-table givenname,sn,company,telephonenumber,mail `
    | export-csv -Delimiter `t -NoTypeInformation -Path c:\scripts\adexport.csv

I get a correct number of rows with no data, except some identifier (which makes sense - since the object isn't being passed into export-csv, just a line of text).

How can I export the specific fields to a file?

I am using Quest's ActiveDirectory powershell CMDLETs (http://www.quest.com/powershell/activeroles-server.aspx) to get the data from AD.

share|improve this question
add comment

1 Answer

up vote 5 down vote accepted

You want to use the Select-Object cmdlet in place of Format-Table. This should work for you:

| select-object givenname,sn,company,telephonenumber,mail `
| export-csv -Delimiter `t -NoTypeInformation -Path c:\scripts\adexport.csv
share|improve this answer
    
Awesome! Thanks so much! –  Tim Jun 4 '10 at 20:46
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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