• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

How to convert Table Data to CSV?

M

Mihail Stacanov

#1
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/tutorial...d-f5396edc2e39/reverse-phone-number-look.aspx
 

My Computer

T

Tome Tanasovski

#2
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/tutorial...d-f5396edc2e39/reverse-phone-number-look.aspx
> .
>
 

My Computer

M

Marjan Repiè

#3
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/tutorial...d-f5396edc2e39/reverse-phone-number-look.aspx
 

My Computer

Users Who Are Viewing This Thread (Users: 1, Guests: 0)