Copying files to a server using PowerShell Sessions
Written on October 11, 2017

In an environment with good security practice applied, you’ll likely find you can’t copy files to a secure server over RDP or via the usual methods:

Fortunately, WMF5 brings a new capability to PowerShell; the ability to copy files into and out of a PowerShell session. This is super easy to demonstrate:

$session = New-PSSession -ComputerName MyServer
Copy-Item -Path "C:\myfile.txt" -Target "C:\SomeServerFolder" -ToSession $session

You can use the Copy-Item cmdlet as per normal, just add the -ToSession parameter and pass in a PowerShell session. You’ll even get a pretty progress bar if you decide to copy large or multiple files.

Comments/questions

There's no commenting functionality here. If you'd like to comment, please either mention me (@chris@aus.social) on Mastodon or email me. I don't have any logging or analytics running on this website, so if you found something useful or interesting it would mean a lot to hear from you.