Windows Vista Forums

CSV headers

  1. #1


    PSApple Guest

    CSV headers

    There has to be an easy way to grab all the header names from a import-csv?

    ex: myfile.csv
    code,name,state,zip
    34,mike,co,80525
    68,jim,co,80528

    and do $mydata= import-csv myfile.csv, how do I get out the names of the
    headers
    I'm tring to get the equivilant of $headNames= $("code",name","State","Zip")





      My System SpecsSystem Spec

  2. #2


    Shay Levi Guest

    Re: CSV headers

    Hi PSApple,

    Each header is represneted by a NoteProperty member, you can use get-member
    to list them:


    $csv = import-csv myfile.csv
    $headres = $csv | Get-Member -MemberType NoteProperty | foreach {$_.name}
    $headres


    -----
    Shay Levi
    $cript Fanatic
    http://scriptolog.blogspot.com
    Hebrew weblog: http://blogs.microsoft.co.il/blogs/scriptfanatic



    > There has to be an easy way to grab all the header names from a
    > import-csv?
    >
    > ex: myfile.csv
    > code,name,state,zip
    > 34,mike,co,80525
    > 68,jim,co,80528
    > and do $mydata= import-csv myfile.csv, how do I get out the names of
    > the
    > headers
    > I'm tring to get the equivilant of $headNames=
    > $("code",name","State","Zip")


      My System SpecsSystem Spec

  3. #3


    Shay Levi Guest

    Re: CSV headers

    Small typo:

    $headres -shouldBe $headers

    -----
    Shay Levi
    $cript Fanatic
    http://scriptolog.blogspot.com
    Hebrew weblog: http://blogs.microsoft.co.il/blogs/scriptfanatic



    > Hi PSApple,
    >
    > Each header is represneted by a NoteProperty member, you can use
    > get-member to list them:
    >
    > $csv = import-csv myfile.csv
    > $headres = $csv | Get-Member -MemberType NoteProperty | foreach
    > {$_.name}
    > $headres
    > -----
    > Shay Levi
    > $cript Fanatic
    > http://scriptolog.blogspot.com
    > Hebrew weblog: http://blogs.microsoft.co.il/blogs/scriptfanatic

    >> There has to be an easy way to grab all the header names from a
    >> import-csv?
    >>
    >> ex: myfile.csv
    >> code,name,state,zip
    >> 34,mike,co,80525
    >> 68,jim,co,80528
    >> and do $mydata= import-csv myfile.csv, how do I get out the names of
    >> the
    >> headers
    >> I'm tring to get the equivilant of $headNames=
    >> $("code",name","State","Zip")


      My System SpecsSystem Spec

  4. #4


    Brandon Shell [MVP] Guest

    Re: CSV headers

    You could use something like this.

    Import-Csv C:\Data\Scripts\testme.txt | get-member -type properties |
    foreach-object{$_.name}

    When you use import-csv it creates and object using the CSV headers as the
    properties and the values are attained from the csv.

    "PSApple" <mapplebee@xxxxxx> wrote in message
    news:u$PESVlPIHA.748@xxxxxx

    > There has to be an easy way to grab all the header names from a
    > import-csv?
    >
    > ex: myfile.csv
    > code,name,state,zip
    > 34,mike,co,80525
    > 68,jim,co,80528
    >
    > and do $mydata= import-csv myfile.csv, how do I get out the names of the
    > headers
    > I'm tring to get the equivilant of $headNames=
    > $("code",name","State","Zip")
    >
    >
    >
    >

      My System SpecsSystem Spec

  5. #5


    Umesh Thakur Guest

    RE: CSV headers

    try this:
    $mydata= import-csv myfile.csv
    $mydata | gm | Where-Object { $_.memberType -eq "NoteProperty" } |
    Select-Object name

    when you import-csv, PS will add the fields as member of array $mydata and
    they will be of "NoteProperty" type.

    --
    Umesh

    "Old programmers never die. They just terminate and stay resident."



    "PSApple" wrote:

    > There has to be an easy way to grab all the header names from a import-csv?
    >
    > ex: myfile.csv
    > code,name,state,zip
    > 34,mike,co,80525
    > 68,jim,co,80528
    >
    > and do $mydata= import-csv myfile.csv, how do I get out the names of the
    > headers
    > I'm tring to get the equivilant of $headNames= $("code",name","State","Zip")
    >
    >
    >
    >
    >

      My System SpecsSystem Spec

  6. #6


    Kiron Guest

    Re: CSV headers

    $headNames = (gc myfile.csv -t 1).split(',') -replace '^\s'

    --
    Kiron

      My System SpecsSystem Spec

CSV headers

Similar Threads
Thread Forum
only headers
Hi all, I'm running windows 7 Home Premium. When I open Live Mail I only get headers. The error message reads, There was an error opening this...
Live Mail
Headers in WLM
Does anybody know if it is possible to change headers in WLM when responding to an email or a newsgroup message ? Thanks. -- Bernard Cordier...
Live Mail
How to see headers
I was wondering if WLM allows you to see the headers of an email message. OE used to have a function "View all headers" or something of that nature,...
Live Mail
Headers Only
I am suddenly getting only the headers synchronizing and no bodies are accessible. Any ideas?
Live Mail
headers...
HOW DO YOU COPY THE HEADERS OF A EMAIL 2 SEND ON 2 SOME1
Vista mail
Cannot view All Headers?
I am unable to view the source, or even select "All headers" from the View menu of *any* email, past or present. The menu item is always greyed out....
Live Mail
Headers
Is it possible to view e-mail headers only in Windows Mail without downloading the whole e-mail ?
Vista mail