I have a quick script written to compare file differences across servers, and then give a prompt for whether to mirror the changes. I'd like it to intelligently NOT prompt for copying if there aren't any changes.
The script:
robocopy "$cSource" "$cDestination" /E /L /FP
$cDecision = Read-host "Continue = 1, anything else = Stop"
if ($cDecision -eq "1") {
robocopy "$cSource" "$cDestination" /MIR /FFT /Z /W:5 /MT:64 /XX /log:$cLogLocation
Invoke-item $cLogLocation
}
else { Write-host "Quit!" }
I'd like to have Powershell not ask to continue if Robocopy reports 0 for Mismatch, Failed, Extras, and Copied. It's not very important for this particular project, but I can think of a couple useful uses for such a check. Thanks!
Best Answer
Finally something people didn't answer in 10 seconds! I used your issue to continue to learn more about Powershell. The following works for me, I hope to see how others will slim down this code:
Note: I have changed the regular expression above from a period to a space immediately before the asterisk. This eliminates the risk of catching 'files' or 'dirs' or 'totals' in a filename/path. The original line is below for posterity.
jski 2014/07/16
$robo_results = $robo_test -match '^(?=.?\b(Total|Dirs|Files)\b)((?! Files).)$'