18 July 2016

How do I - Exclude certain file types from a XCopy folder sync?

When you're managing multiple SharePoint farms that rely on custom, in-house developed Powershell modules, keeping these modules up to date across the entire enterprise can be a tricky prospect.  This is usually where I employ some Powershell with calls to XCopy.

XCopy is a very powerful tool for synching files between systems.  As you can see from its documentation page, there are many command switches for it.  The tricky thing is usually when you're trying to sync folders that contain Powershell scripts, but these scripts generate log files.  You want to sync the .ps1 files, but not the .log files.  How do we do that then?

This is where the /exclude: switch comes into play.  You can create a text file containing the extensions you wish to exclude.  Then you simply pass the text file to the /exclude: switch thus:

xcopy S:\Corne\Scripts\*.* T:\Scripts /E /I /F /H /R /Y /d /exclude:Exclusions.txt

Its important to remember that the exclusion will do a simple path match on the values specified in exclusions.txt.  As such, having the file content defined thus:


will exclude anything that matches ".log" somewhere in the path of the file e.g. files ending in ".logger", ".logs", ".log2, ".log" etc. will all be excluded from XCopy.  This can be resolved by simply adding a backslash to the back of the extension thus:


Now XCopy will only ignore files with a ".log" extension.


SharePoint Remote Event Receivers are DEAD!!!

 Well, the time has finally come.  It was evident when Microsoft started pushing everyone to WebHooks, but this FAQ and related announcement...