Paste files from local PC to Remote Desktop using Powershell

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.
Andy BrownDeveloperAsked:
Who is Participating?
Ben Personick (Previously QCubed)Connect With a Mentor Lead Network EngineerCommented:
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

ITSysTechConnect With a Mentor Senior Systems AdministratorCommented:
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 BrownDeveloperAuthor Commented:
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.
Worried about phishing attacks?

90% of attacks start with a phish. It’s critical that IT admins and MSSPs have the right security in place to protect their end users from these phishing attacks. Check out our latest feature brief for tips and tricks to keep your employees off a hackers line!

David Johnson, CD, MVPOwnerCommented:
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.
Andy BrownDeveloperAuthor Commented:
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 BrownDeveloperAuthor Commented:
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 Network EngineerCommented:
hey Andy, glad that was helpful to you :)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.