Created
July 2, 2021 22:53
-
-
Save tylerapplebaum/d8caf3e852aa9280bf931ec8e4a25424 to your computer and use it in GitHub Desktop.
Sync items using a PowerShell wrapper around robocopy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#https://social.technet.microsoft.com/wiki/contents/articles/1073.robocopy-and-a-few-examples.aspx | |
#http://www.luisrocha.net/2008/12/robocopy-error-error-5-0x00000005.html | |
# Robocopy switches used: | |
#/MIR - mirror directory structure (including empty) | |
#/COPY:DT - excludes copying permissions | |
#/XA:H - excludes hidden files | |
#/W:5 - wait 5 seconds on a failure | |
#/XJD - exclude junction points | |
#/XD - exclude directory | |
Function Sync-Documents { | |
param( | |
[Parameter(HelpMessage="Specify the source path to data you wish to copy",Mandatory=$True)] | |
[ValidateScript({Test-Path $_ -PathType Container})] | |
[string]$SourceDir, | |
[Parameter(HelpMessage="Specify the destination path of data to be copied to",Mandatory=$True)] | |
[System.IO.FileInfo]$DestDir | |
) | |
robocopy.exe $SourceDir $DestDir /MIR /COPY:DT /XA:H /W:5 /XJD /XD "C:\Users\$env:username\Documents\my-app" | |
} | |
Sync-Documents -SourceDir "C:\Users\$env:username\Documents" -DestDir "W:\My Documents\Documents-Backup" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment