Eliminate # Comment from exported CSV

This topic contains 8 replies, has 5 voices, and was last updated by  Tim Ker 1 year, 3 months ago.

  • Author
    Posts
  • #53212

    Jim
    Participant

    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

    Daniel Krebs
    Moderator

    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

    • This reply was modified 1 year, 3 months ago by  Daniel Krebs.
    • #53230

      Jim
      Participant

      Thanks!

  • #53241

    Don Jones
    Keymaster

    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

      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.

      • This reply was modified 1 year, 3 months ago by  Jim.
  • #53278

    Jim
    Participant

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

    • This reply was modified 1 year, 3 months ago by  Jim.
  • #53410

    Richard Siddaway
    Moderator

    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

    Daniel Krebs
    Moderator

    Excellent suggestion, Richard. Thanks very much.

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

    • #53497

      Tim Ker
      Participant

      I personally prefer a web based view:

      Get-help Export-Csv -Online
      

You must be logged in to reply to this topic.