Eliminate # Comment from exported CSV

Welcome Forums General PowerShell Q&A Eliminate # Comment from exported CSV

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

 
Participant
2 years, 3 months ago.

  • Author
    Posts
  • #53212
    Jim

    Participant
    Points: 0
    Rank: Member

    Chapter 6 lab, "Learning Powershell in a month of lunches" asks the question "5. Is there a way to eliminate the # comment line from the top of an exported CSV file? That line normally contains type information, but what if you wanted to omit that from a particular file?" but provides no answer. Anyone?

  • #53227

    Moderator
    Points: 24
    Team Member
    Rank: Member

    You can provide the parameter -NoTypeInformation to the cmdlets ConvertTo-Csv and Export-Csv.

    $data | ConvertTo-Csv -NoTypeInformation
    $data | Export-Csv -Path C:\test.csv -NoTypeInformation

    • #53230
      Jim

      Participant
      Points: 0
      Rank: Member

      Thanks!

  • #53241

    Keymaster
    Points: 1,673
    Helping HandTeam Member
    Rank: Community Hero

    The goal was to have you read the help for the command and discover that on your own :). Meant to be empowering.

    • #53256
      Jim

      Participant
      Points: 0
      Rank: Member

      Thanks Don. Your comment in the book about reading the help ran through my mind after I posted it. And yet I'm not sure what to type after Get-Help.

  • #53278
    Jim

    Participant
    Points: 0
    Rank: Member

    I went back through the chapters and don't see where we covered -NoType or how to Get-Help on a switch

  • #53410

    Participant
    Points: 0
    Rank: Member

    try

    Get-help Export-Csv -full

    Read the whole entry – especially what each of the parameters do

    Its actually a good idea to read through the help for any new cmdlet you come across to make sure you understand how it works an what your choices are

  • #53413

    Moderator
    Points: 24
    Team Member
    Rank: Member

    Excellent suggestion, Richard. Thanks very much.

    Honestly I should add something similar to every post as a signature.

    • #53497

      Participant
      Points: 0
      Rank: Member

      I personally prefer a web based view:

      Get-help Export-Csv -Online
      

The topic ‘Eliminate # Comment from exported CSV’ is closed to new replies.