Monday, September 3, 2012

Robocopy log Analyzing with Powershell Script

Below PowerShell Script will analyze Robocopy log file and will give summarized report.

$files=get-childitem "<logfile location>" 
$pattern1 = $null 
$pattern2 = $null 
$pattern3 = $null 
$pattern4 = $null 
foreach ($file in $files) 
    { 
    write-host "Working on" $file 
    select-string $file -pattern " Started : " 
    select-string $file -pattern "Source : " 
    select-string $file -pattern "Dest : " 
    $pattern1 = select-string $file -pattern "Files :  " 
    $pattern1 = $pattern1.tostring() -replace '\s+', " " 
    $pattern2 = $pattern1.tostring().split(" ") 
    write-host "Total files on source:`t" $pattern2[3] 
    write-host "Total files copied:`t`t" $pattern2[4] 
    write-host "Total files skipped:`t" $pattern2[5] 
    write-host "Total files failed:`t`t" $pattern2[7] 
    $pattern3 = select-string $file -pattern "Bytes : " 
    $pattern3 = $pattern3.tostring() -replace " 0 ", " 0 m " 
    $pattern3 = $pattern3.tostring() -replace '\s+', " " 
    $pattern4 = $pattern3.tostring().split(" ") 
    write-host "Total bytes on source:`t" $pattern4[3] $pattern4[4] 
    write-host "Total bytes copied:`t`t" $pattern4[5] $pattern4[6] 
    write-host "Total bytes skipped:`t" $pattern4[7] $pattern4[8] 
    write-host "Total bytes failed:`t`t" $pattern4[11] $pattern4[12] 
    $error1 = select-string $file -pattern "0x00000002" 
    write-host "File not found error :"$error1.count 
    $error2 = select-string $file -pattern "0x00000003" 
    write-host "File not found errors :"$error2.count 
    $error3 = select-string $file -pattern "0x00000005" 
    write-host "Access denied errors :"$error3.count 
    $error4 = select-string $file -pattern "0x00000006" 
    write-host "Invalid handle errors :"$error4.count 
    $error5 = select-string $file -pattern "0x00000020" 
    write-host "File locked errors :"$error5.count 
    $error6 = select-string $file -pattern "0x00000035" 
    write-host "Network path not found errors :"$error6.count 
    $error7 = select-string $file -pattern "0x00000040" 
    write-host "Network name unavailable errors :"$error7.count             
    $error8 = select-string $file -pattern "0x00000070" 
    write-host "Disk full errors :"$error8.count 
    $error9 = select-string $file -pattern "0x00000079" 
    write-host "Semaphore timeout errors :"$error9.count 
    $error10 = select-string $file -pattern "0x00000033" 
    write-host "Network path errors :"$error10.count 
    $error11 = select-string $file -pattern "0x0000003a" 
    write-host "NTFS security errors :"$error11.count        
    $error12 = select-string $file -pattern "0x0000054f" 
    write-host "Internal errors :"$error12.count 
    select-string $file -pattern "Ended : " 
    write-host "=============================" 
    sleep 2 
    }

No comments: