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.

This entry was posted in PowerShell v5. Bookmark the permalink.

6 Responses to Copy files over PS remoting sessions

  1. Marekku[MSFT] says:

    Hi, have you seen any way to force “any file” to be copied? It seems that current release of PS limits this functionality to only files that you know the names of… using something like *.csv returns an error…

  2. Andrew K. says:

    How do you send it to Multiple computers in Parallel?

  3. Guilherme Felix says:

    Is that possible to use this new feature to copy from a server with Powershell 5.0 to another one with Powershell 2.0?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s