Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - Parse Log files into a strongly type Object

Reply
 
Old 01-11-2007   #1 (permalink)
Karlos


 
 

Parse Log files into a strongly type Object

Fellow humans,

I'm trying to process the following data from a log file into a
strongly typed object for further analysis:-

05-Nov-06 12:00:06.287 ( -1 4360 4356)
dual_flsrv.exe:dual_flsrv.c,v:267: connection accepted from client
SVRPCSA address 158.89.5.16
05-Nov-06 12:00:06.287 ( -1 4360 8220)
dual_flsrv.exe:rcv_u_fl.c,v:165: serving client SVRPCSA address
158.89.5.16

This is the script that I'm using to parse the data into an object:-

switch -file c:\svrlog.txt -regex {

"^\s*(\d\d-\w\w\w-\d\d)\s*(\d\d:\d\d:\d\d\.\d\d\d)\s*(.*[0-9]\))\s*(.*)"
{
$obj = New-Object -TypeName System.Management.Automation.PSObject
$prop = New-Object System.Management.Automation.PSNoteProperty
'Date',
$matches[1]
$obj.PSObject.Properties.Add($prop)
$prop = New-Object System.Management.Automation.PSNoteProperty
'Time',
$matches[2]
$obj.PSObject.Properties.Add($prop)
$prop = New-Object System.Management.Automation.PSNoteProperty
'Code',
$matches[3]
$obj.PSObject.Properties.Add($prop)
$prop = New-Object System.Management.Automation.PSNoteProperty
'Desc',
$matches[4]
$obj.PSObject.Properties.Add($prop)
$obj
}

}
The question is, how can I collect the output of the above script into
a collection of an object for further analysis. e.g say sort on code
and list.

say like $x = switch -file c:\svrlog.txt -regex { .........} (which
doesn't work.)

Any idea's

Many thanks in advance


My System SpecsSystem Spec
Old 01-11-2007   #2 (permalink)
Kbgo


 
 

RE: Parse Log files into a strongly type Object

Please ignore as it's been answered below. The problem is I published via
google groups, and that doesn't seem to work correctly. Which is strange for
Google. ;-)

"Karlos" wrote:

> Fellow humans,
>
> I'm trying to process the following data from a log file into a
> strongly typed object for further analysis:-
>
> 05-Nov-06 12:00:06.287 ( -1 4360 4356)
> dual_flsrv.exe:dual_flsrv.c,v:267: connection accepted from client
> SVRPCSA address 158.89.5.16
> 05-Nov-06 12:00:06.287 ( -1 4360 8220)
> dual_flsrv.exe:rcv_u_fl.c,v:165: serving client SVRPCSA address
> 158.89.5.16
>
> This is the script that I'm using to parse the data into an object:-
>
> switch -file c:\svrlog.txt -regex {
>
> "^\s*(\d\d-\w\w\w-\d\d)\s*(\d\d:\d\d:\d\d\.\d\d\d)\s*(.*[0-9]\))\s*(.*)"
> {
> $obj = New-Object -TypeName System.Management.Automation.PSObject
> $prop = New-Object System.Management.Automation.PSNoteProperty
> 'Date',
> $matches[1]
> $obj.PSObject.Properties.Add($prop)
> $prop = New-Object System.Management.Automation.PSNoteProperty
> 'Time',
> $matches[2]
> $obj.PSObject.Properties.Add($prop)
> $prop = New-Object System.Management.Automation.PSNoteProperty
> 'Code',
> $matches[3]
> $obj.PSObject.Properties.Add($prop)
> $prop = New-Object System.Management.Automation.PSNoteProperty
> 'Desc',
> $matches[4]
> $obj.PSObject.Properties.Add($prop)
> $obj
> }
>
> }
> The question is, how can I collect the output of the above script into
> a collection of an object for further analysis. e.g say sort on code
> and list.
>
> say like $x = switch -file c:\svrlog.txt -regex { .........} (which
> doesn't work.)
>
> Any idea's
>
> Many thanks in advance
>
>

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
discovering the type of an object PowerShell
parse files VB Script
Re: Unable to cast COM object of type 'ADODB.RecordsetClass' to class type 'System.Object[]' .NET General
Parse XML files from Powershell? PowerShell
Parse Log files into a strongly type Object PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46