Author Posts

July 16, 2016 at 6:31 am

Hi,
I have two IIS logfiles. I am searching a string name: "externalsystemorderservice" and convertin those IISlogfiles to CSV files.
$log = Get-ChildItem -Path C:\Temp\Test\0.log
$col = {@()}.invoke()
switch -Regex -File $log
{
'#Fields.*' {$fields = $_}
'\d+.*externalsystemorderservice.*' {$col.add($Matches[0])}
}
$fields = $fields -replace '#Fields:'
$fields = $fields.trim() -split ' '
$col -replace ' ',',' | convertfrom-csv -Header $fields |
Export-Csv -Path C:\Temp\Test\0.csv -NoTypeInformation

The same way, I am doing for other logfile as-well.

Problem is, I have common fields in both CSV files & that needs to be merged & come as third CSV file.
Common fields: date,time,s-computername,s-ip,time-taken.

-Kalyan

July 18, 2016 at 1:51 pm

Run your switch statement for each log file then export the results. Make the following changes.

$logs = Get-ChildItem -Path \\path\to\iislogs
$col = {@()}.invoke()

foreach ($log in $logs){
switch -Regex -File $log
{
'#Fields.*' {$fields = $_}
'\d+.*externalsystemorderservice.*' {$col.add($Matches[0])}
}
}