Starting with version 5 PowerShell (included with Windows Server 2016, loaded as part of WMF 5 for earlier versions ), this is possible with remote interaction. The advantage of this is that it works, even if for some reason you cannot access shared resources.
For this to work, PowerShell 5 or higher must be installed in the local session where the copying starts. You do not need to install PowerShell 5 for a remote session β it works with PowerShell versions 2 and Windows Server versions starting from 2008 R2. [one]
From server A, create a session on server B:
$b = New-PSSession B
And then from A:
Copy-Item -FromSession $b C:\Programs\temp\test.txt -Destination C:\Programs\temp\test.txt
Copying elements to B is done using -ToSession . Note that local paths are used in both cases; You must keep track of which server you are on.
[1]: when copying from or to a remote server with only PowerShell 2 installed, beware of this error in PowerShell 5.1 , which at the time of writing means that recursive copying of files does not work with -ToSession , apparently copying doesnβt at all I work with -FromSession .
Jeroen Mostert Aug 24 '16 at 11:48 2016-08-24 11:48
source share