Move files via PowerShell Remote Session
Sometimes we need to transfer a file from one location to another with PowerShell. In my testing lab, I use a Hyper-V Server without any GUI but I need to be able to transfer ISO files to the server. I will explain step-by-step how to perform this action.
We can do this using the commands below.
First setup the PowerShell remote connection by saving it in the $ExternalServer variable.
$ExternalServer = New-PSSession -ComputerName "JV-DC01.justinverstijnen.nl"Replace the computername JV-DC01.justinverstijnen.nl with the computer name of your server. Log in when needed/being asked to.
Then you should have a connection to the remote server. Now we can setup our parameters, like the source file and the destination path:
$SourceFile = "C:\Temp\Windows.iso"
$Destination = "D:\ISO-files"Now we have setup these settings. Note that I place the file on the D: volume on the remote server. Now we can run the command below to copy the file from the local machine right onto the server:
Copy-Item $SourceFile -Destination $Destination -ToSession $ExternalServerThis copy action can take a while, depending on your servers and connection between them.
End of the page 🎉
You have reached the end of the page. You can navigate through other blog posts as well, share this post on X, LinkedIn and Reddit or return to the blog posts collection page. Thank you for visiting this post.