Robocopy job template and log parser
A safer Robocopy job template with dry-run review, log capture, exit-code interpretation, and migration evidence.
Good For
- file share migration
- large copy jobs
- backup staging
- scheduled transfer review
- copy failure evidence
How to Use It
- Start with a preview command that includes `/L` so Robocopy lists intended work without copying or deleting files.
- Review source, destination, exclusions, retry behavior, and whether permissions, timestamps, or owner data should be copied.
- Avoid `/MIR` unless delete behavior has explicit approval and a restore path.
- Run the real copy with `/TEE` and a log file so console output and durable evidence are both captured.
- Parse the run log and exit code before deciding whether the job succeeded, partially succeeded, or needs rerun.
- Store preview and run logs with the migration or backup ticket.
Execution Modes
- local
- remote-single-host
- remote-host-list
Inputs and Outputs
Inputs
- source path
- destination path
- CSV or TXT job list
- exclusion list
- log path
Outputs
- verbose-console
- log-file
- operator-notes
Command Starter
Example pattern only. Adjust for your environment before running.
# ---------------------------------------------------------------------
# Operator inputs
# ---------------------------------------------------------------------
$Source = 'C:\Source'
$Destination = '\\server\share'
$LogRoot = 'C:\Temp'
$PreviewLog = Join-Path $LogRoot 'robocopy-preview.log'
$RunLog = Join-Path $LogRoot 'robocopy-run.log'
# ---------------------------------------------------------------------
# Phase A  dry-run preview. /L lists work without copying or deleting.
# ---------------------------------------------------------------------
& robocopy $Source $Destination /E /L /R:2 /W:5 /TEE /LOG:$PreviewLog
# ---------------------------------------------------------------------
# Phase B  approved copy execution. This changes the destination path.
# ---------------------------------------------------------------------
& robocopy $Source $Destination /E /R:2 /W:5 /COPY:DAT /DCOPY:DAT /TEE /LOG:$RunLog
$RobocopyExitCode = $LASTEXITCODE
# ---------------------------------------------------------------------
# Lightweight log summary. A fuller pack can parse totals more deeply.
# ---------------------------------------------------------------------
$SummaryLines = Select-String -Path $RunLog -Pattern 'Dirs :','Files :','Bytes :','Times :','Ended :'
[pscustomobject]@{
Source = $Source
Destination = $Destination
PreviewLog = $PreviewLog
RunLog = $RunLog
RobocopyExitCode = $RobocopyExitCode
SummaryLineCount = $SummaryLines.Count
}
$SummaryLinesValidation
- Preview log matches the intended source, destination, and exclusion scope.
- Run log shows acceptable copied, skipped, failed, and mismatch counts for the job goal.
- Sample files open from the destination and permissions behave as expected.
Reporting
- Attach preview and run logs to migration tickets.
- Record the Robocopy exit code separately from human pass/fail interpretation.
- Promote repeated use into a migration evidence pack with normalized return-code and copy-count parsing.
Safety Notes
- Preview with `/L` before copying.
- Treat `/MIR`, `/PURGE`, and overwrite-heavy jobs as change-window work with backup or restore evidence.
- Keep the previous source available until destination validation and owner signoff are complete.