Export Information to CSV?

Welcome Forums General PowerShell Q&A Export Information to CSV?

This topic contains 4 replies, has 4 voices, and was last updated by

3 years, 10 months ago.

  • Author
  • #24125

    Points: 0
    Rank: Member

    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

    Points: 0
    Rank: Member


    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

    Points: 0
    Rank: Member

    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

    Points: 1,811
    Helping HandTeam Member
    Rank: Community Hero

    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

    Points: 0
    Rank: Member

    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!

The topic ‘Export Information to CSV?’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort