Tutorial: How to Copy File to Remote Computer with PowerShell

This guide explains how to copy a file to a remote computer with PowerShell, using commands like New-PSSession and Copy-Item. For those looking for a simpler solution, AnyViewer offers a quick and easy way to transfer files with its user-friendly interface.

Ellie

By Ellie / Updated on January 7, 2025

Share this: instagram reddit

How Do ICopy a File from Local to Remote Server Using PowerShell?

PowerShell is a robust command-line shell and scripting language tailored for system administrators and developers. One of its most practical features is the ability to effortlessly transfer files to remote computers. The Copy-Item command is commonly used for this purpose, particularly when handling multiple computers within a network.

two remote computers

The PowerShell Copy-Item command offers several key benefits:

  • Automation: Scripts can automate the file copying process, reducing the chances of human error.
  • Batch Operations: It enables efficient copying of files or folders across multiple computers simultaneously.
  • Security: PowerShell ensures secure file transfers.
  • Error Handling: Scripts can monitor file transfers, quickly identifying and resolving any issues.

This guide will demonstrate how to use PowerShell to copy files to a remote computer, highlighting its efficiency and security.

How to Copy File to Remote Computer Using PowerShell

Let's briefly outline the basic steps to copy file from remote server to local using PowerShell. We'll then dive into a detailed explanation in the following section.

Step

Command

Cmdlet

1. Create a New Session

New-PSSession

Establishes a remote session.

2. Verify Session

Get-PSSession

Confirms session properties.

3. Copy Files

Copy-Item

Executes file transfers.

4. Confirm Transfer

Invoke-Command

Validates file transfer success.

5. End Session

Remove-PSSession

Closes the remote session

Step 1. Press Win + X and select PowerShell (Admin) to launch PowerShell. Establish a connection to the remote machine using the following command:

  • $Session = New-PSSession -ComputerName "ComputerName" -Credential "Credential"

Step 2. Check the session properties using:

  • Get-PSSession

Step 3. Execute the file transfer with the Copy-Item cmdlet:

  • Copy-Item "C:\Folder\file.txt" -Destination "D:\DestinationFolder\" -ToSession $Session

Use the FromSession parameter to copy files from the remote system to your local machine.

Step 4. Ensure the file transfer was successful:

  • Invoke-Command -ScriptBlock { Get-ChildItem -Path "C:\DestinationFolder\file.txt" } -Session $Session

Step 5. Terminate the session with:

  • Remove-PSSession -Session $Session

Additional Commands for Copying Files

The "Copy-Item" cmdlet in PowerShell is a versatile tool for transferring items between locations. It's not limited to copying a single file to a remote machine—it also supports a variety of operations within a remote session. Below are some examples and notes on its usage:

Operation

Command

Notes

Copy a folder to a remote computer

Copy-Item "D:\Folder\" -Destination "C:\Folder_Copy\" -ToSession $Session

Subfolders and files won't be copied unless you include the "-Recurse" parameter.

Recursively copy an entire folder's contents

Copy-Item "D:\Folder\" -Destination "C:\Folder_Copy\" -ToSession $Session -Recurse

The "-Recurse" parameter ensures that the full directory structure, including subfolders, is copied.

Copy and rename a file on the remote machine

Copy-Item "D:\Folder\test.txt" -Destination "C:\Folder_Copy\test_copy.txt" -ToSession $Session

Avoid adding a trailing slash (/) at the end of file or folder names when renaming.

Copy a file from a remote machine to local

Copy-Item "C:\Folder\test.txt" -Destination "D:\Folder_Copy\" -FromSession $Session

Use the "-FromSession" parameter to transfer files from the remote system back to your local machine.

 

These commands provide flexibility for managing files remotely, simplifying tasks in a networked environment.

Alternative: Transferring Files to a Remote Computer with Remote Access Software

For those less familiar with PowerShell commands, transferring files to a remote computer might seem daunting. Fortunately, there are simpler alternatives available, such as using third-party remote access software with built-in file transfer features.

AnyViewer is a highly effective remote access software for users looking to smooth connectivity and quick file transfers on a remote computer. It simplifies the process of migrating files with a straightforward PC-to-PC file transfer feature. With a transfer speed of up to 10 MB/s and the ability to handle large files (up to 1TB), AnyViewer ensures fast and reliable file movement.

Download Freeware Win PCs & Servers
Secure Download

In addition to file transfer, AnyViewer also provides useful features like unattended access, screen sharing, and black screen mode, enhancing the remote access experience. These features, combined with AnyViewer’s user-friendly interface and advanced security measures, make it a top choice for seamless remote access and file transfers.

Conclusion

In conclusion, knowing how to copy a file to a remote computer with PowerShell offers a powerful and secure way to transfer files. By following the steps with commands like New-PSSession, Copy-Item, and Invoke-Command, you can efficiently manage file transfers to remote systems. However, for those looking for an easier alternative, AnyViewer simplifies the process with fast file transfer speeds and additional remote access features. Whether using PowerShell or remote access software, both methods ensure reliable and secure file transfers to remote computers.