Skip to content

Instantly share code, notes, and snippets.

@eosfor
Created October 2, 2016 18:26
Show Gist options
  • Select an option

  • Save eosfor/ba2baf5e1ecf6b28764611ad99b5dfd8 to your computer and use it in GitHub Desktop.

Select an option

Save eosfor/ba2baf5e1ecf6b28764611ad99b5dfd8 to your computer and use it in GitHub Desktop.
$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 ';'
}
@eosfor
Copy link
Copy Markdown
Author

eosfor commented Nov 4, 2017

Parses robocopy logs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment