header image

Copy files over PS remoting sessions

Posted by: | May 28, 2015 Comments Off on Copy files over PS remoting sessions |

One neat feature of the April 2015 WMF 5.0 preview is that you can copy files over a remoting session.

First create a session to a remote machine

$cs = New-PSSession -ComputerName W12R2SUS


Define the source and destination for the copy.  Use –ToSession to determine the remoting session you will use to determine the remote machine

Copy-Item -Path C:\Source\test.csv -Destination C:\Source\test.csv -ToSession $cs


You use –FromSession to copy from a remote machine

Copy-Item -Path C:\Source\srv.csv -Destination C:\Source\srv.csv -FromSession $cs


What you can’t do is copy from one session to another

$cs2 = New-PSSession -ComputerName server02

£> Copy-Item -Path C:\Source\*.csv -Destination C:\Source\ -FromSession $cs2 -ToSession $cs
Copy-Item : ‘-FromSession’ and ‘-ToSession’ are mutually exclusive and cannot be specified at the same time.

under: PowerShell v5

Comments are closed.