Paste files from local PC to Remote Desktop using Powershell

Andy Brown
Andy Brown used Ask the Experts™
I am looking at the various way to copy files from a users local PC to a specific folder location - on a Remote Server.  Essentially, it would work in the following way:

  • User copies files on local PC
  • They switch to the RDP server
  • Press a button on our application that runs a script and pastes the file into a specific folder

We need this paste function to run int the background and I was wondering if we could use Powershell to do this.  Incidentally, our server is running 2012 R2.
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
ITSysTechSenior Systems Administrator
This will work for your situation. Make sure you start at the third paragraph which would work with copying a file to a server. Link

"Now, imagine that I want to copy this file to other servers. If you are using the PowerShell 5.0, now the Copy-Item command supports copying files from one machine to another through -ToSession and -FromSession parameters. As the name suggests, the -ToSession parameter expects a session with the destination computer where the file will be copied.To create the session, I used the following command:"

$ Session = new-PSSession -ComputerName PowerShellAzureMachine -Credential $ cred

Now we have the session, the second step is to perform the file copy via -ToSession parameter:

Copy-Item -Path C:\temp\localfile.txt -Destination C:\localfile.txt -ToSession $ session
Andy BrownDeveloper


Thank you so much for coming back to me - it looks interesting and I'll take another look tomorrow (when I'm a little more awake).

The problem that I have is, that on the users local PC - I can't install any software and need to rely on them to manually copy the files to the clipboard.  However, once they are on the RDP - I can do whatever needs to be done.

Thanks again for coming back to me so quickly - I need to sign off now and get some dinner.
Top Expert 2016

powershell is included with all current windows operating systems the problem is that scripts are disabled
The clipboard is not usable here. as the clipboard contains the contents of the file.. copy and paste operates differently depending upon the context, within a file it copies the text to the clipboard otherwise it just buffers the selection.
Exploring ASP.NET Core: Fundamentals

Learn to build web apps and services, IoT apps, and mobile backends by covering the fundamentals of ASP.NET Core and  exploring the core foundations for app libraries.

Lead SaaS Infrastructure Engineer
If you want to give them a folder that sync on button click on the remote system this can be done.

To be clear it only works if they are connecting to the RDP server through an actual RDP session, and you allow remote drive mapping, then you can have a CMD script or Powershell script do the copy using the TSClient mapping for the remote drives.

  1. User Copies the file to C:\SharetoRDP\
  2. User logs on to RDP
  3. User clicks script or manually runs copy command

Example of a CMD needed to copy all files on the user's local system "C:\SharetoRDP" to The RDP Server under "C:\CopiedFromRDP", in the RDP session you refer to these mapped drives as "\\tsclient\[Drive Letter]" so "\\tsclient\C\SharetoRDP"

Robocopy "\\tsclient\C\SharetoRDP" "C:\CopiedFromRDP" * /S /E 

Open in new window

Andy BrownDeveloper


Thanks David - good information
Ben - that looks like a really good option, I'll take a look

Thank you everyone - I'll report back....
Andy BrownDeveloper


Thank you everyone for your help.  In the end, I just opted to share the C drive and use Ben's solution.
Ben Personick (Previously QCubed)Lead SaaS Infrastructure Engineer

hey Andy, glad that was helpful to you :)

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial