13 Mar 2015 @ 6:24 PM 

if you ever used Robocopy you are certainly familiar with the large amount of information that is written to the log files.
The disadvantage of these log files is that you have to search true a lot of information to find error messages.

Recently i received a project to migrate data between 2 file server (linux to Windows).
because there was a assumption that there were problems with path lengths,we need to find these and take some manual actions.

the quickest way to do this was to make a copy of files between the servers.
the only problem is that you will get large log files with information.
For this project i got log files from almost 400MB with information
this means almost 3 million lines of logging each share.

as you understand there is nobody who wants to search manually true this logs i made a short Powershell function to search true the log files for error messages.
only thing you need to do is load the following script

function Analyse-Robocopy {
 This function analyse output logging for robocopy 
 This function analyse output logging for robocopy 
 Analyse-Robocopy -sourcefile d:\robocopy.log -resultfile d:\robocopy-result.log -messages Error
 This command wil generate a new logfile with all Error messages found in sourcefile
 Analyse-Robocopy -sourcefile d:\robocopy.log -messages Error
 This command wil generate a new logfile with all Error messages found in sourcefile and place it in C:\temp\Robocopy-Analyse.log
 when the folder C:\Temp not exist the folder will be created
 .Parameter sourcefile 
 The name and location of the file you want to analyse
 .Parameter resultfile
 The location where the result will be saved.
 Default value is c:\Temp\Robocopy-Analyse.log
 .Parameter Messages 
 specify the sort messages you want to find
 Default value is Error
 NAME: Analyse-Robocopy
 AUTHOR: Marco van Wyngaarden 
 LASTEDIT: 03/16/2015 14:40 
 KEYWORDS: Robocopy, Analyser
Robocopy Analyser
#> Param( [Parameter(Position=0, Mandatory=$True, ValueFromPipeline=$True)] [string]$sourcefile, $resultfile = "c:\temp\robocopy-Analyse.log", [ValidateSet("Error","success")] [String] $messages = "Error" ) #check if resultfile is given otherwise fill resultfile with default value if ($resultfile -eq "c:\temp\robocopy-Analyse.log"){ if (!(Test-Path -Path "c:\temp")){ New-Item -ItemType directory -Path "c:\temp" | Out-Null } } #check message type and search logfile if ($messages -eq 'Error'){ $output = Get-ChildItem $sourcefile | Select-String -Pattern '(error 123)| (error 32)' $output | Out-File $resultfile -Width 1200 } else{ $output = Get-ChildItem $sourcefile | Select-String -Pattern '(New File) | (New Dir )' $output | Out-File $resultfile -Width 1200 } Write-Host " ------------------------------------------------" Write-Host " ROBOCOPY LOG FILE ANALYSER REPORT" Write-Host " ------------------------------------------------" Write-Host Write-Host "" Counted $output.count $messages messages."" Write-Host "" Results are saved in $resultfile"" Write-Host Write-Host " ------------------------------------------------" }

How it works ?
simple load the function to your session
and run function as followed :

Analyse-Robocopy -sourcefile D:\logging\robocopy.log

When it is completed you will receive a new log file in C:\temp
here you find a file named Robocopy-analyse.log

Posted By: Marco van Wyngaarden
Last Edit: 16 Mar 2015 @ 03:00 PM

EmailPermalinkComments (0)
Categories: Powershell

 Last 50 Posts
Change Theme...
  • Users » 1
  • Posts/Pages » 3
  • Comments » 0
Change Theme...
  • VoidVoid « Default
  • LifeLife
  • EarthEarth
  • WindWind
  • WaterWater
  • FireFire
  • LightLight