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
Read-only command: verify target and scope
# --------------------------------------------------------------------- # 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. # ---------------------------------------------------------------------
Manual or UI step
& robocopy $Source $Destination /E /L /R:2 /W:5 /TEE /LOG:$PreviewLog
Configuration or code example: review values for your environment
# --------------------------------------------------------------------- # Phase B  approved copy execution. This changes the destination path. # ---------------------------------------------------------------------
Manual or UI step
& robocopy $Source $Destination /E /R:2 /W:5 /COPY:DAT /DCOPY:DAT /TEE /LOG:$RunLog
Read-only command: verify target and scope
$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
}Manual or UI step
$SummaryLines
Validation
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
The template is supporting material, not the production cutover decision workflow. Preview with /L first; a real Robocopy execution writes destination data and must use the migration evidence pack for validation and rollback decisions.
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.
