How to copy files and folder tree to a remote machine?

I have two machines, Server A and Server B, and I want to copy all the files and the folder tree from server A to server B using PowerShell.

I tried the command below, but it only copies the files in the folder and does not create the folder tree:

Copy-Item E:\TestSource\* //TestDestination/ -recurse -force
+5
source share
4 answers

If you have a source and destination folder, you can use the following command:

robocopy $source $dest /e

If you need more information about the team, you can use robocopy /?or visit the Robocopy documentation at Windows Server Technet, Robocopy .

+4
source
Get-ChildItem \\server_a\c$ -Recurse | % {
   $dest = Join-Path -Path \\server_b\c$ -ChildPath (Split-Path $_.FullName -NoQualifier)

   if (!(Test-Path $dest))
   {
      mkdir $dest
   }

   Copy-Item $_.FullName -Destination $dest -Force
}

Split-Path -NoQualifier . ( ) .

+1

I would suggest that you have rights to 2 servers

Get-ChildItem "\ SERVER_A \ C $" -Recurse | Copy-Item -Destination "\ SERVER_B \ C $"

-3
source

Do not use the PowerShell cmdlet Copy-Item. Find a third-party mirroring / synchronization tool. We use RoboCopy .

-3
source

All Articles