The delta sync command in PowerShell is not a single built-in cmdlet but refers to using PowerShell to perform incremental (delta) synchronization—copying only changed files or objects since the last sync. This is commonly done with tools like robocopy, rsync via WSL, or the Robust Copy module, often for backup, migration, or cloud sync scenarios. To achieve this, you typically combine native PowerShell cmdlets (like Get-ChildItem with -File and -Recurse) with comparison logic or leverage robust external utilities. Below is a practical, step-by-step guide for implementing delta sync using the most reliable, widely available method: robocopy via PowerShell.

What You'll Need

  • Windows PC or server (Windows 7 or later, including Windows 10/11 and Windows Server 2012/2016/2019/2022)
  • PowerShell 5.1 or PowerShell 7+ (installed and accessible)
  • Source and destination folders (local, network share, or mapped drive)
  • Administrative privileges if syncing to protected locations (e.g., Program Files, system drives)
  • Basic understanding of file paths and PowerShell syntax

Step-by-Step

  1. Open PowerShell with appropriate permissions: Press Win + X, then select Windows PowerShell (Admin) or Terminal (Admin) if using the newer Windows Terminal. If syncing to system or protected folders, admin rights are required to avoid access-denied errors. For user data (e.g., Documents), standard user privileges usually suffice.
  2. Verify robocopy is available: Run robocopy /? | Select-Object -First 1 in PowerShell. This should return Usage : ROBOCOPY <source> <destination> [file] [options]. Robocopy is included by default in Windows Vista and later—no extra install needed. If the command isn’t recognized, you may be on an extremely minimal Windows image (e.g., Server Core without tools), where you’d need to add the Desktop Experience feature.
  3. Define your source and destination paths: Store them in variables for clarity and reusability. For example: $source = "C:\Users\YourName\Documents" $dest = "D:\Backup\Documents" Ensure paths exist or create them first using New-Item -ItemType Directory -Path $dest -Force.
  4. Run the delta sync command: Use robocopy with the /MIR (mirror) and /XO (exclude older) options to sync only new or changed files, and optionally /R:3 /W:5 to retry failed copies up to 3 times with 5-second waits. A typical command: robocopy $source $dest /MIR /R:3 /W:5 The /MIR flag mirrors the source directory structure, deleting files in the destination that no longer exist in the source (use with caution). For a safer, non-destructive sync, use /E instead of /MIR to copy subdirectories (including empty ones) without deleting extras in the destination.
  5. Add logging for verification: Append a log file to track what changed. Modify the command to: robocopy $source $dest /MIR /R:3 /W:5 /LOG:C:\Temp\delta-sync.log The log shows files copied, skipped (unchanged), and any errors. Review it after each run to confirm delta behavior—look for entries like Same (unchanged) or New File.
  6. Make it reusable with a script (optional but recommended): Save the following as Delta-Sync.ps1: param( [Parameter(Mandatory=$true)][string]$Source, [Parameter(Mandatory=$true)][string]$Destination, [string]$LogPath = "C:\Temp\delta-sync-$(Get-Date -Format 'yyyyMMdd-HHmm').log" ) if (-not (Test-Path $Source)) { Write-Error "Source path not found: $Source"; exit 1 } if (-not (Test-Path $Destination)) { New-Item -ItemType Directory -Path $Destination -Force | Out-Null } robocopy $Source $Destination /MIR /R:3 /W:5 /LOG:$LogPath Write-Host "Sync complete. Log saved to $LogPath" -ForegroundColor Green Run it with .& Delta-Sync.ps1 -Source "C:\Data" -Destination "D:\Backup".

Common Mistakes

  • Using /MIR unintentionally: /MIR deletes files in the destination that don’t exist in the source. If you only want to add new/changed files without removing anything, use /E instead of /MIR. Always test with a small folder first.
  • Ignoring trailing backslashes: Robocopy treats paths with and without trailing backslashes differently (e.g., C:\Source vs C:\Source\). Keep paths consistent to avoid creating nested subfolders like C:\Dest\Source.
  • Not checking for permission issues: Files in use, locked, or with restrictive ACLs may fail silently. Check the log for ERROR 5 (0x00000005) (Access Denied) and adjust permissions or exclude problem files with /XF or /XD.
  • Assuming PowerShell cmdlets do delta natively: Copy-Item does not support delta sync—it copies everything. Using Compare-Object to compare files is possible but slow and memory-heavy for large datasets; robocopy is far more efficient and battle-tested for this task.

Tips

  • Use /FFT for file time tolerance: Add /FFT to use FAT file times (2-second precision), which helps avoid false positives when syncing between NTFS and FAT drives.
  • Schedule regular syncs: Save your script and use Task Scheduler to run it daily/weekly. Set the trigger to run whether user is logged on or not, and use the least-privilege account possible.
  • Exclude large or irrelevant files: Add /XF *.tmp *.log or /XD \$Recycle.Bin System Volume Information to skip system folders and temp files.
  • Monitor bandwidth with /IPG: On slow networks, use /IPG:100 to insert 100-millisecond gaps between packets, reducing network congestion.
  • Test dry-runs first: Add /L (list only) to preview changes without copying: robocopy $source $dest /MIR /L /LOG:preview.log. This shows what would be copied, skipped, or deleted.

Troubleshooting

If your delta sync doesn’t behave as expected, follow these checks in order:

  1. Verify paths and existence: Run Test-Path $source and Test-Path $dest in PowerShell to confirm both paths exist and are accessible. A typo (e.g., C:\Soure) causes robocopy to treat the source as a file filter, breaking the sync.
  2. Check the log: Open the log file (e.g., notepad C:\Temp\delta-sync.log) and look for the summary section at the bottom. It lists copied, skipped, and mismatched files. High Same counts confirm delta behavior; high Extra counts with /MIR indicate deletions.
  3. Run without /MIR for safety: Temporarily replace /MIR with /E to avoid unintended deletions. If sync completes without deleting files, the issue is likely /MIR’s destructive nature.
  4. Test with a single file: Create a tiny test file in the source (e.g., echo "test" > $source\test.txt), run sync, and confirm it appears in the destination. If not, permissions or path issues are likely.
  5. Check for file locks: Use Process Explorer (Microsoft Sysinternals) to search for handles on locked files in the source or destination. Close the relevant process or reboot if needed.
  6. Try robocopy without PowerShell: Run the exact robocopy command directly in Command Prompt (cmd.exe) to rule out PowerShell-specific quirks (e.g., variable expansion issues).

Frequently Asked Questions

Does PowerShell have a native delta sync cmdlet?

No. PowerShell doesn’t include a built-in cmdlet for delta sync. You must use robocopy, third-party tools (like FreeFileSync), or write custom logic with Compare-Object—which is inefficient for large data sets.

Is robocopy still supported on Windows 11?

Yes. Robocopy is included in all modern Windows versions, including Windows 11 and Windows Server 2022. Microsoft continues to maintain it as part of the Windows SDK and Server tools.

How do I sync only files changed in the last 24 hours?

Robocopy doesn’t filter by age directly, but you can combine it with PowerShell. For example: Get-ChildItem $source -Recurse -File | Where-Object { $_.LastWriteTime -gt (Get-Date).AddDays(-1) } | ForEach-Object { robocopy $_.DirectoryName $dest $_.Name /XO }. However, this is slower than using robocopy alone; for most cases, /MIR with /FFT is sufficient.

Can I sync to OneDrive or SharePoint?

Not directly. robocopy can sync to a mapped OneDrive folder (e.g., Z:\), but it won’t trigger cloud upload until the file is fully written. For SharePoint, use Microsoft Graph API or the SharePoint Sync Engine—not robocopy—for reliable delta sync.

What’s the difference between /MIR and /E?

/E copies all subdirectories, including empty ones, but never deletes files in the destination. /MIR mirrors the source exactly—it deletes files/folders in the destination that no longer exist in the source. Use /E for backups where you want to preserve extra files.

Why are some files showing as "Same" but still copied?

This can happen due to file time precision differences (e.g., NTFS vs. FAT) or file attributes (like archive bit). Adding /FFT (FAT file times) and /FFT /XO (exclude older) often resolves this. If files are identical but timestamps differ slightly, robocopy may re-copy them without /FFT.