replace robocopy options with copy-item




I want to get rid of robocopy in some old scripts and use powershell copy-item instead.


Here is a typical line :

.\robocopy.exe "\\$sourceserver\$sourcefolder" "\\$targetserver\$targetfolder" *.* /r:2 /w:5 /e /purge


/purge ask to remove anything at the target that doesn't exists at source. Basically it does a folder sync more than a source folder content copy to the target.

/e copies also empty folders

/r:2 retries twice if copy errors while /w:5 asks to wait 5 second between every try


I mostly concerned with the /purge option. I don't see any option in copy-item that would do a sync of the source and target folder. 


Do I need to create a function to do it myself or is there any native way of doing it that I'm not aware of?


This page suggest that it is not handled by default (see the very last proposal) :
How to keep 2 folders in sync using powershell script - Stack Overflow


Thank you.



0 Replies