Blog Post

ITOps Talk Blog
1 MIN READ

How to Copy files from Windows to Linux using PowerShell Remoting

thomasmaurer's avatar
thomasmaurer
Icon for Microsoft rankMicrosoft
Jun 27, 2019

With the release PowerShell Core 6, the PowerShell Team brought PowerShell to other platforms like Linux and macOS. This new cross-platform approach allows users to take advantage of some pretty cool features. In this blog post, I am quickly going to show you, how you can use PowerShell Remoting to copy files from Windows to Linux systems.

 

PowerShell Core enables a new feature, PowerShell Remoting Over SSH, SSH remoting lets you do basic PowerShell session remoting between Windows and Linux machines.

 

As you already know from Windows PowerShell Remoting, we can use a PowerShell remoting session to copy files to a remote system, using the Copy-Item cmdlet with the -ToSession parameter.

 

 

 

First, you need to make sure that you have installed and configured PowerShell and SSH Remoting. You can find more here: Setup PowerShell SSH Remoting in PowerShell 6

 

After that you can create a new PowerShell session:

 

$s = New-PSSession -HostName 137.117.136.159 -UserName Thomas

 

You can then simply use the Copy-Item cmdlet to copy the file to the specific session:

 

Copy-Item .\windows.txt /home/thomas -ToSession $s

 

I hope this gives you a great option to copy files from Windows to Linux using PowerShell Remoting. Thanks to Matjaz Znidar (Microsoft PFE) for the great idea.

Updated Jun 27, 2019
Version 3.0
  • CaptainCrewe's avatar
    CaptainCrewe
    Copper Contributor

    This was a great help to me as I tried to create a script for managing the deployment of some .NET Core projects from Windows 10 to a Raspberry Pi 4.  For users of the Pi that follow, I would note that the destination should be /home/pi/XXX (assuming you have established your session as pi).  You need to specify the full path and there may several home directories under /home.

     

    Many thanks

  • Athithya's avatar
    Athithya
    Brass Contributor

    It is very helpful. I use WinSCP typically to copy files from windows to linux but after this has been landed, I'll prefer powershell remoting.