Exporting specific fields with powershell's export-csv

33,578

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:
33,578

Related videos on Youtube

Tim
Author by

Tim

Updated on September 17, 2022

Comments

  • Tim
    Tim 5 months

    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.