I'm trying to copy files from serverA to serverB using Powershell. Both servers belong to our hosting provider so copying files from A to B is very fast compared to copying files from my local box to either server. I figured I could use Powershell to run a remote command on serverA and copy the files to serverB. This is what I came up with:
$SourceServerName = "serverA"
$SourceContentPath = "\\serverA\c$\testSrc"
$DestinationContentPath = "\\serverB\c$\testDest"
Invoke-Command -ComputerName $SourceServerName -ScriptBlock {param ($SourcePath,$InstallPath)
Copy-Item -Path $SourcePath\* -Destination $InstallPath -Recurse
} -ArgumentList $SourceContentPath, $DestinationContentPath
But I get an error "System.Management.Automation.RemoteException: Access to the path 'testDest' is denied.
I'm an admin and WinRM is configured properly on both boxes. If I try to copy files remotely inside the same server (i.e. from \\serverA\c$\testSrc to \\serverA\c$\testDest) everything works fine.
What's the proper way to do this?