Export to .csv remove header and

Welcome Forums General PowerShell Q&A Export to .csv remove header and

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

 
Participant
4 months, 3 weeks ago.

  • Author
    Posts
  • #121249

    Participant
    Points: 55
    Rank: Member

    I am trying to script an export from AD to a separate DB to run daily.  I need to remove the header and some other gibberish so

    I can import into the DB cleanly, is there a way to do this?  The first 2 lines shown below I need to try to get rid of.

    #TYPE Selected.Microsoft.ActiveDirectory.Management.ADUser
    givenname surname department emailaddress office

    Here is my code:

    Get-ADUser -Filter {department -like "*"} -Properties givenname, surname, department, emailaddress, office |Select-Object givenname, surname, department, emailaddress, office |Export-Csv "c:\emailaddress.csv"

     

     

  • #121255

    Participant
    Points: 1,166
    Helping Hand
    Rank: Community Hero

    Each reasonable tool able to import standards-compliant CSV files should be able to deal with this information. Nevertheless you can easily avoid to have one of them by using the parameter -NoTypeInformation. I reccommend that you carefully read the help for the cmdlets you use, including the examples, to learn how to use them.
    To remove the headers from a csv file usually does not make any sense.
    BTW: When you post code plaease format it as code. Thanks

  • #121266

    Participant
    Points: 457
    Helping Hand
    Rank: Contributor

    If you need to remove the header row you'll need to do a little extra work. As Olaf mentioned, the -NoTypeInformation will get rid of the metadata.

    For the header row itself, you need to use a slightly different cmdlet to let you trim the file before export:

  • #121272

    Participant
    Points: 55
    Rank: Member

    BTW: When you post code plaease format it as code. Thanks

    Sorry, I did see that in the "Read before you post"  Thanks for the help Olaf and Joel, much appreciated

The topic ‘Export to .csv remove header and’ is closed to new replies.

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