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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ITSysTechSenior 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.
David Johnson, CD, MVPRetiredCommented:
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.
Angular Fundamentals

Learn the fundamentals of Angular 2, a JavaScript framework for developing dynamic single page applications.

Ben Personick (Previously QCubed)Lead SaaS Infrastructure 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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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 SaaS Infrastructure EngineerCommented:
hey Andy, glad that was helpful to you :)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.