Eliminate # Comment from exported CSV

This topic contains 8 replies, has 5 voices, and was last updated by Profile photo of Tim Ker Tim Ker 3 weeks, 1 day ago.

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #53212
    Profile photo of Jim
    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
    Profile photo of Daniel Krebs
    Daniel Krebs
    Participant

    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 3 weeks, 4 days ago by Profile photo of Daniel Krebs Daniel Krebs.
    #53230
    Profile photo of Jim
    Jim
    Participant

    Thanks!

    #53241
    Profile photo of Don Jones
    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
    Profile photo of Jim
    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 3 weeks, 4 days ago by Profile photo of Jim Jim.
    #53278
    Profile photo of Jim
    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 3 weeks, 4 days ago by Profile photo of Jim Jim.
    #53410

    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
    Profile photo of Daniel Krebs
    Daniel Krebs
    Participant

    Excellent suggestion, Richard. Thanks very much.

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

    #53497
    Profile photo of Tim Ker
    Tim Ker
    Participant

    I personally prefer a web based view:

    Get-help Export-Csv -Online
    
Viewing 9 posts - 1 through 9 (of 9 total)

You must be logged in to reply to this topic.