How to replicate/copy files and folder structure between two different Windows based machines using PowerShell.

Many times we feel the need of copying files between two machines and also keeping the same folder structure between two machines. For example, consider the following use cases:

  1. Replicating the production/non-production environment’s directory structure on a blank virtual machine.
  2. Copying files and folders from one location to another location.
  3. Copying files from production/non-production machine to your local machine.

Now to solve the above problem, I have created a PowerShell script that can replicate a given list of directories present on the source machine to another target machine. I have also added an option to choose if we want to just replicate the folder structure to the target machine or we want to copy the files present in those folders too.