How to convert Table Data to CSV?


  1.    18 Dec 2009 #1
    Mihail Stacanov Guest

    How to convert Table Data to CSV?


    Hi guys.

    How can I convert the output of "net session" to csv or objects?

    PS C:\> net session

    Computer User name Client Type Opens Idle time

    -------------------------------------------------------------------------------
    \\192.168.0.165 xxxxxxxxxx Windows 2002 Serv 1 00:00:00
    \\192.168.0.217 yyyyyyyy Windows 2002 Serv 1 00:50:44
    \\192.168.0.222 qqqqqqqqq Windows 2002 Serv 1 00:16:59
    \\192.168.0.245 wwwwwwwwwwww Windows 2002 Serv 1 00:00:00
    \\192.168.0.55 eeeeeeeeee Windows 2002 Serv 1 00:11:21
    \\192.168.0.72 tttttt Windows 2002 Serv 1 00:05:21
    \\192.168.0.81 uuuuuuuuu Windows 2002 Serv 1 00:05:21
    \\192.168.0.83 iiiiiii Windows 2002 Serv 1 00:00:00
    The command completed successfully.


    Submitted via EggHeadCafe - Software Developer Portal of Choice
    Reverse Phone Number Lookup WebService
    http://www.eggheadcafe.com/tutorials...mber-look.aspx
      My System SpecsSystem Spec

  2.    18 Dec 2009 #2
    Tome Tanasovski Guest

    RE: How to convert Table Data to CSV?


    I'm not sure if there's an easier way, but this will work. I used net
    session with /list because it's easier to parse and you don't get your values
    truncated:

    $objects = @()
    net session /list| foreach {
    if ($_ -match "User name\s*(\S*[\s\S]*)") {
    $obj = New-Object PSObject -Property @{
    "User name" = $matches[1]
    "Computer" = ""
    "Guest logon" = ""
    "Client type" = ""
    "Idle time" = ""
    }
    }
    if ($_ -match "Computer\s*(\S*[\s\S])") {
    $obj.Computer = $matches[1]
    }
    if ($_ -match "Guest logon\s*(\S*[\s\S]*)") {
    $obj."Guest logon" = $matches[1]
    }
    if ($_ -match "Client type\s*(\S*[\s\S]*)") {
    $obj."Client type" = $matches[1]
    }
    if ($_ -match "Idle time\s*(\S*[\s\S]*)") {
    $obj."Idle time" = $matches[1]
    $objects += $obj
    }
    }

    $objects

    "Mihail Stacanov" wrote:

    > Hi guys.
    >
    > How can I convert the output of "net session" to csv or objects?
    >
    > PS C:\> net session
    >
    > Computer User name Client Type Opens Idle time
    >
    > -------------------------------------------------------------------------------
    > \\192.168.0.165 xxxxxxxxxx Windows 2002 Serv 1 00:00:00
    > \\192.168.0.217 yyyyyyyy Windows 2002 Serv 1 00:50:44
    > \\192.168.0.222 qqqqqqqqq Windows 2002 Serv 1 00:16:59
    > \\192.168.0.245 wwwwwwwwwwww Windows 2002 Serv 1 00:00:00
    > \\192.168.0.55 eeeeeeeeee Windows 2002 Serv 1 00:11:21
    > \\192.168.0.72 tttttt Windows 2002 Serv 1 00:05:21
    > \\192.168.0.81 uuuuuuuuu Windows 2002 Serv 1 00:05:21
    > \\192.168.0.83 iiiiiii Windows 2002 Serv 1 00:00:00
    > The command completed successfully.
    >
    >
    > Submitted via EggHeadCafe - Software Developer Portal of Choice
    > Reverse Phone Number Lookup WebService
    > http://www.eggheadcafe.com/tutorials...mber-look.aspx
    > .
    >
      My System SpecsSystem Spec

  3.    22 Dec 2009 #3
    Marjan Repič Guest

    Re: How to convert Table Data to CSV?


    Hello

    You can simply use net session > c:\net_session.csv

    Marjan

    "Mihail Stacanov" je napisal v sporočilo
    news:2009121844720m.stacanov@newsgroup ...

    > Hi guys.
    >
    > How can I convert the output of "net session" to csv or objects?
    >
    > PS C:\> net session
    >
    > Computer User name Client Type Opens Idle
    > time
    >
    > -------------------------------------------------------------------------------
    > \\192.168.0.165 xxxxxxxxxx Windows 2002 Serv 1
    > 00:00:00
    > \\192.168.0.217 yyyyyyyy Windows 2002 Serv 1
    > 00:50:44
    > \\192.168.0.222 qqqqqqqqq Windows 2002 Serv 1
    > 00:16:59
    > \\192.168.0.245 wwwwwwwwwwww Windows 2002 Serv 1
    > 00:00:00
    > \\192.168.0.55 eeeeeeeeee Windows 2002 Serv 1
    > 00:11:21
    > \\192.168.0.72 tttttt Windows 2002 Serv 1
    > 00:05:21
    > \\192.168.0.81 uuuuuuuuu Windows 2002 Serv 1
    > 00:05:21
    > \\192.168.0.83 iiiiiii Windows 2002 Serv 1
    > 00:00:00
    > The command completed successfully.
    >
    >
    > Submitted via EggHeadCafe - Software Developer Portal of Choice
    > Reverse Phone Number Lookup WebService
    > http://www.eggheadcafe.com/tutorials...mber-look.aspx
      My System SpecsSystem Spec

How to convert Table Data to CSV?

Similar Threads
Thread Forum
RE: How to convert Table-Format Data to CSV-Format?
Prevous version needed fine tuning --did it in a hurry. Now it split lines even when the value part is null and removes the dash from property...
PowerShell
RE: How to convert Table-Format Data to CSV-Format?
# change this line switch -r (gc <AV Log File's path here>) { # to: switch -r -file <AV Log File's path here> { # better way to read huge...
PowerShell
RE: How to convert Table-Format Data to CSV-Format?
Try this: $out = @() switch -r (gc <AV Log File's path here>) { '^Date:' { $obj = new-object psObject } '^+' { $prop, $val =...
PowerShell
Goofed up GPT partition table... Data Lost?
I have a 320 GB drive in a USB external converter (the big plastic shell that turns any IDE drive into a USB 2.0 drive). I did something I...
Vista General
Goofed up GPT partition table... Data Lost?
I have a 320 GB drive in a USB external converter (the big plastic shell that turns any IDE drive into a USB 2.0 drive). I did something I...
Vista file management
Adding data to a hash table
I have imported a csv using import-csv $clcode = import-csv $csvlocation | select clcode $clcode results are a list of 6 digit numbers, for the...
PowerShell
Creating files from Data Table
i have an interesting need and one that i am almost there with but can't get the last bit. i am querying the database to get a results set. Within...
PowerShell

Our Sites
  • Ten Forums
  • Eight Forums
  • Seven Forums
  • Help Me Bake
  • Site Links
  • Contact Us
  • Privacy and Cookies
  • About Us
    Windows Vista Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

    © Designer Media Ltd
    All times are GMT -5. The time now is 08:05.
    .