Skip to content

Instantly share code, notes, and snippets.

@tylerapplebaum
Created October 24, 2019 21:18
Show Gist options
  • Select an option

  • Save tylerapplebaum/0520bd4281a2d6c4b0acce72b160b89d to your computer and use it in GitHub Desktop.

Select an option

Save tylerapplebaum/0520bd4281a2d6c4b0acce72b160b89d to your computer and use it in GitHub Desktop.

Revisions

  1. Tyler Applebaum revised this gist Oct 24, 2019. 1 changed file with 6 additions and 6 deletions.
    12 changes: 6 additions & 6 deletions Sync-Documents.ps1
    Original file line number Diff line number Diff line change
    @@ -1,12 +1,12 @@
    #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
    #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

    Function Sync-Documents {
    param(
  2. Tyler Applebaum created this gist Oct 24, 2019.
    23 changes: 23 additions & 0 deletions Sync-Documents.ps1
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    #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

    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
    }

    Sync-Documents -SourceDir "C:\Users\$env:username\Documents" -DestDir "W:\My Documents\Documents-Backup"