I need to copy a folder which contains subfolders with files to a shared folder on another machine. During that the script should create a custom sub folder in each destination folder and place files there.
I hope this example clatifies the task:
For the following source folder:
--Logs ----Application ------Service --------Log1.txt --------Log2.txt ------WebSite --------Log1.txt --------Log2.txt
Destination folder should be created in the following way:
--Logs ----Application ------Service --------Machine1 ----------Log1.txt ----------Log2.txt ------WebSite --------Machine1 ----------Log1.txt ----------Log2.txt
As you see at the bottom level subfolders Machine1
have been created.
Can you please provide an example of PowerShell script which performes that?
I investigated input parameters in ROBOCOPY command. It seems it doesn't allow to do that straightforward.
Also I know that I can symply iterate through all folder structure, create required sub folders and copy files to each subfolder. But it seems to be a too 'long' way. So I want to know if I'm missing anything. Maybe there is a better smart way to do that.
I'd suggest to use
robocopy
for replicating the contents of the subfolders: