Export Information to CSV?

This topic contains 4 replies, has 4 voices, and was last updated by Profile photo of Jay Jones Jay Jones 1 year, 6 months ago.

  • Author
  • #24125
    Profile photo of Jay Jones
    Jay Jones

    Hello i am trying to export my AD users to a CSV of a particular format so that i can upload them to a third party application. So far i can get the users and format them in a table with the format i want using..

      Get-ADUser -Filter * -SearchBase "OU=Current Staff,OU=Our Organisation,DC=OurOrg,DC=COM" | Format-Table Name,GivenName,Surname,UserPrincipalName -a -HideTableHeaders   

    Great i have all the columns and data i need. I just want to export this to a csv that already has the headers 'Username' 'First Name' Last Name' 'Email'. When i pipe the above to..

      Export-Csv -Path "C:\Holding\Okta AD Exports\third-party-template.csv" 

    I get a load of guff in the CSV file and the headers have gone (see atatched). What am i doing wrong? Is there a way to add custom headers when i format the table so i can just export them to a new CSV? I think its because it cant match up the data with the headers but not sure why.

    Thanks in advance!

  • #24128
    Profile photo of Ondrej Zilinec
    Ondrej Zilinec


    Is this what you wanted:

    Get-ADUser -Filter * -SearchBase "OU=Current Staff,OU=Our Organisation,DC=OurOrg,DC=COM" | Select-Object Name,GivenName,Surname,UserPrincipalName | Export-Csv -Path "C:\Holding\Okta AD Exports\third-party-template.csv"
  • #24129
    Profile photo of H Man
    H Man

    remove format table its not needed

    Get-ADUser -Filter * -SearchBase "OU=Current Staff,OU=Our Organisation,DC=OurOrg,DC=COM" |  Export-Csv -Path "C:\Holding\Okta AD Exports\third-party-template.csv" -NoTypeInformation

    The only thing you can pipe after format-table is out-file, other than that its the end of the road

  • #24131
    Profile photo of Don Jones
    Don Jones

    As a note, consider reading "The Big Book of PowerShell Gotchas." It's free, very short, and it explains why Format-Table was messing you up.

  • #24149
    Profile photo of Jay Jones
    Jay Jones

    Thanks for your replies everyone, sorry for the delay in getting back to you. You have resolved the issue for me. Ill be sure to get that book!

You must be logged in to reply to this topic.