6

I'm using an older version of robocopy that includes percentages in the log even if the /NJH and /NJS paramters are set. So I'd like to remove the percentages from the log:

            72880735    H:\1.txt
100%  
            33038490    H:\10.txt
100%  
            64878348    H:\2.txt
100%  
            25875810    H:\3.txt
  0%  
100%  

I've tried with

(Get-Content $logfile) | Where-Object {
    $_ -match '[\s](\d{1,})(\s+)(\w\W\W.+)'
} | Set-Content $logfile

But that results in

            72880735    H:\1.txt
            33038490    H:\10.txt 
            64878348    H:\2.txt
            25875810    H:\3.txt
  0%  

So I get the 100%'s stripped out, but not the 0%.

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
RMK
  • 107
  • 1
  • 1
  • 11
  • Try `Where{$_ -match '[\s](\d{1,})(\s+)(\w\W\W.+)' -and $_ -notlike '*%*'}` Edit: I looked again and that doesn't make sense. You should not get `0%` with that regex. I even tested it on [RegEx101](https://regex101.com/r/gvLGw7/1). – TheMadTechnician Jul 12 '17 at 23:44
  • @TheMadTechnician - Some day, robocopy will understand a PS-Drive name longer than one letter. Will the regex work then? – lit Jul 13 '17 at 01:39
  • That worked @TheMadTechnician! – RMK Jul 17 '17 at 08:10

1 Answers1

14

/njh and /njs have nothing to do with the percentage information. You need to suppress progress output by adding the option /np to your robocopy commandline.

From the documentation:

/np Specifies that the progress of the copying operation (the number of files or directories copied so far) will not be displayed.


Edit: After taking a look at your actual commandline it looks like /np is not compatible with /mt. Adding the latter parameter makes robocopy display progress output even if /np is present. If you don't require running multi-threaded I'd remove that parameter (add /ndl to prevent directories from appearing in the output).

I would also recommend using splatting instead of putting the parameter list into a single string:

$params = $src, $dest, ('/LOG:"{0}"' -f $logpath), '/L', '/NP', '/NC', '/BYTES',
          '/NJH', '/NJS', '/NDL', '/E', '/MOVE', '/XC', '/XN', '/XO', '/XD',
          $excludedFoldersList

& robocopy @params

If for some reason you must use multi-threading you should be able to remove progress information from the log after completion like this:

(Get-Content $logpath) | Where-Object {
    $_ -notmatch '^\s*\d{1,3}%\s*$'
} | Set-Content $logpath
Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
  • I should have mentioned that, but the /NP paramter is also set. I mentioned `/njh` and `/njs` as I saw it mentioned in another post that setting these would suppress the percentages. – RMK Jul 17 '17 at 08:08
  • @Moller If that parameter were set you wouldn't be getting progress output in your log. I'm not making this up. Please show your full `robocopy` commandline and tell us the (file) version number of the executable. – Ansgar Wiechers Jul 17 '17 at 09:00
  • I don't think you are, not at all. I'm pretty new to powershell so I'm sure I messed up somewhere. It's the Win 8.1 `robocopy` version from 2014, `ProductVersion: 6.3.9600.16384` – RMK Jul 17 '17 at 09:24
  • That version should behave exactly as I described. Please show your full commandline. – Ansgar Wiechers Jul 17 '17 at 09:32
  • `'"{0} " "{1} " /LOG:"{2}" /L /NP /NC /BYTES /NJH /NJS /MT /E /MOVE /XD {3} /XC /XN /XO' -f $src, $dest, $logPath, [string]::Join(' ', $excludedFoldersList)` So i use it with some variables and execute it with `Start-Process`. – RMK Jul 17 '17 at 09:40