Windows Vista Forums

How to convert Table Data to CSV?

  1. #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.   


  3. #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

  4. #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? PowerShell
RE: How to convert Table-Format Data to CSV-Format? PowerShell
RE: How to convert Table-Format Data to CSV-Format? PowerShell
Adding data to a hash table PowerShell
Creating files from Data Table PowerShell