M365 & Exchange PowerShell Builder
Common admin tasks as ready-to-run PowerShell
Pick options for mirroring, retries, multithreading, logging and exclusions visually and get a correct Robocopy or rsync command, with an explanation of each flag.
robocopy D:\Shares\Finance \\nas01\Backups\Finance /MIR /COPYALL /DCOPY:DAT /MT:16 /R:3 /W:10 /XJ /XD $RECYCLE.BIN "System Volume Information" /XF *.tmp ~$* /LOG+:C:\Logs\finance-backup.log /NP /TEE /L
/MIRMirror: copy subfolders (including empty ones) AND delete files in the destination that no longer exist in the source/COPYALLCopy data, attributes, timestamps, NTFS permissions, owner and auditing info/DCOPY:DATKeep folder attributes and timestamps too/MT:16Copy with 16 threads at once (1–128); much faster for many small files/R:3Retry a failed file 3 times (the default is 1,000,000)/W:10Wait 10 seconds between retries (the default is 30)/XJSkip junction points, which avoids endless loops through folders like “Application Data”/XD $RECYCLE.BIN "System Volume Information"Exclude these folders (names, wildcards or full paths)/XF *.tmp ~$*Exclude these files (names or wildcards)/LOG+:C:\Logs\finance-backup.logAppend the output to this log file/NPDon’t print per-file percentages, which bloat log files/TEEAlso show the output in the console while logging/LList only: show what would happen without copying, moving or deleting anythingRobocopy exit codes 0–7 mean success (1 = files copied, 2 = extra files found, 3 = both). 8 or above means some files failed. Check this in scripts instead of treating any non-zero code as an error.
Network shares (\\server\share) and remote paths (user@host:/path) both work.
Start with a dry run, especially when mirroring.
Check the log, then run again without the dry-run option.
/E copies all subfolders, including empty ones, and never deletes anything. /MIR does the same but also deletes files in the destination that no longer exist in the source, making an exact mirror.
/MT on its own uses 8 threads; you can set 1 to 128. 8–32 suits most copies. Many small files benefit most; a few huge files gain little.
Robocopy’s exit codes are a bitmap: 0 means nothing needed copying, 1 means files were copied successfully, 2 means extra files were found, and 8 or above means failures. Treat 0–7 as success in scripts.
rsync /data/ dest copies the contents of /data into dest. rsync /data dest copies the folder itself, creating dest/data. It matters most with --delete.
Last updated 4 Dec 2026 · More in Sysadmin & Command Builders
Common admin tasks as ready-to-run PowerShell