Created
October 2, 2016 18:26
-
-
Save eosfor/ba2baf5e1ecf6b28764611ad99b5dfd8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$paths = | |
"C:\SyncLog\logFile1.log", | |
"C:\SyncLog\logFile2.log", | |
"C:\SyncLog\logFile3.log", | |
"C:\SyncLog\logFile4.log", | |
"C:\SyncLog\logFile5.log" | |
$reportsPath = "C:\SyncLog\Reports" | |
foreach ($p in $paths) { | |
$end = select-string -Path $p -Pattern "Ended\s+:" | |
$start = select-string -Path $p -pattern 'Started\s+:' | |
$table = ($start + $end) | sort LineNumber | select -expa line | % {$_.trim()} | |
$ret = @() | |
for ($i=0; $i -le $table.Count; $i++){ | |
if($table[$i] -like "Started*"){ | |
if ($table[$i+1] -like "Ended*"){ | |
$s = [datetime]($table[$i] -replace "Started : ", "") | |
$e = [datetime]($table[$i+1] -replace "Ended : ", "") | |
$ret += [pscustomobject]@{Start=$s; End=$e; Duration = ($e - $s); Status = 'Success'} | |
} | |
else { | |
$s = [datetime]($table[$i] -replace "Started : ", "") | |
if ($i -lt $table.Count-1) { | |
$e = [datetime]($table[$i+1] -replace "Started : ", "") | |
$ret += [pscustomobject]@{Start=$s; End=$null; Duration = ($e - $s); Status = "Failed"} | |
} | |
else{ | |
$s = [datetime]($table[$i] -replace "Started : ", "") | |
$ret += [pscustomobject]@{Start=$s; End=$null; Duration = $null; Status = "Running"} | |
} | |
} | |
} | |
} | |
$fileName = [io.path]::GetFileName($p) | |
$ext = [io.path]::GetExtension($p) | |
$outFile = "$($fileName -replace $ext,'').csv" | |
$ret | export-csv -Path (Join-Path $reportsPath $outFile) -NoTypeInformation -Force -Delimiter ';' | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Parses robocopy logs