0/1 Lessons

Course Introduction

• 5min

0 / 2 lessons complete

Getting Started with Windows PowerShell

• 56min

0 / 8 lessons complete

Getting Help and Finding Commands

• 39min

0 / 6 lessons complete

PowerShell Command Syntax

• 33min

0 / 5 lessons complete

PowerShell Objects and Properties

• 35min

0 / 6 lessons complete

The PowerShell Pipeline

• 24min

0 / 2 lessons complete

PowerShell Providers

• 30min

0 / 5 lessons complete

PowerShell Arrays and Variables

• 28min

0 / 4 lessons complete

PowerShell Loops

• 19min

0 / 3 lessons complete

PowerShell Conditional Statements

• 11min

0 / 1 lessons complete

On Premises Lab Setup

• 36min

0 / 8 lessons complete

Basic Domain Administration with Windows PowerShell

• 2hr 27min

0 / 10 lessons complete

Send Emails with PowerShell

• 22min

0 / 2 lessons complete

PowerShell Desired State Configuration (DSC) Basics

• 1hr 48min

0 / 6 lessons complete

PowerShell Modules

• 58min

0 / 7 lessons complete

Powershell Challenges

• 1hr 55min

0 / 23 lessons complete

Course Conclusion

• 1min

0 / 1 lessons complete

How to Copy Files To-From a Remote Machine using VSC Answer


Q&A (0)

Notes (0)

Resources (0)

Saving Progress...


There are no resources for this lesson.

Notes can be saved and accessed anywhere in the course. They also double as bookmarks so you can quickly review important lesson material.

Create note

How can I Copy files To-From a Remote Machine Using VSC Answer

  • You should have completed the prerequisites from the Copy to-from Challenge.
  • Let’s review – On the Host you have a file called loginfo.txt located in C:\Temp\Local folder.

On the Remote computer you have a file called Kb.pdf located in C:\Temp\Remote folder

  • In this lecture we will use VSC and the Copy-item command to copy files to and from a remote computer.
  •  This lecture is not meant to be part of a VSC course. I just thought you might like to learn a few things about Visual Studio Code.
  •  And all scripts that we will take a look at will work in PowerShell ISE as well as VSC.

If you have already followed the directions from Section 2 called “Setting up Visual Studio Code for Powershell” you will be ready to use these commands.

From the Host computer open VSC.

You will need to create a remote Session to the target computer VSC1 using the New-PSSession cmdlet.
Here is the command line:
I already have my script in the folder section. You can go ahead and Copy and Paste this command into the Terminal section of VSC

   $session = New-PSSession -ComputerName VSC1 -Credential (Get-Credential)

Here is the Explanation:

$session: This is a variable that will store the session object created by New-PSSession. This object will be used to interact with the remote computer.

New-PSSession: This cmdlet is used to create a new PowerShell session that allows you to run commands on a remote computer.

-ComputerName VSC1: Here, you specify the target remote computer's name or hostname, which in this case is "VSC1." This is the computer you want to connect to remotely.

-Credential (Get-Credential): This part of the command is responsible for specifying the credentials to use for the remote session.

Get-Credential: This is a cmdlet used to interactively prompt the user for a username and password. It opens a secure dialog box for you to enter the necessary credentials. The credentials you enter here are the credentials that will be used to authenticate and establish the remote connection to "VSC1."

When you use PowerShell Remoting to copy a file from your local computer to a remote computer, you are running the commands from your local computer, but those commands are executed on the remote computer. You establish a remote session to the target computer, but you remain on your local computer while executing commands.

I’ll go ahead and press F8 and run the command
I’ll type administrator, then the password. Now my remote session has started.

  1. Let’s go ahead and learn how to use the Copy-item command to copy a file from the local computer, to the C:\Temp\remote folder on the remote VM.

Here is the command line and the explanation:

Copy-item -Path C:\Temp\Local\loginfo.txt -Destination c:\Temp\Remote -ToSession $Session

  • Copy-item - This is the cmdlet used to copy files and directories in PowerShell.
  • -Path - This parameter specifies the source file or directory you want to copy. In this case, you are copying the file loginfo.txt located at C:\Temp\Local\ on your local computer.
  • -Destination: This parameter specifies the destination directory where you want to copy the source file or directory. You want to copy it to C:\Temp\Remote on the remote computer.
  • -ToSession: This parameter specifies the PowerShell session (PSSession) that you want to use for the copy operation. You've stored a session object in the $Session variable, which represents your connection to the remote computer.
  • Let’s go ahead and run the Copy-Item command
  • Verify that your file was copied to the C:\Temp\Remote folder on the remote computer.
    There we see loginfo.txt, so that was successful.

  • Now take a look at the command line that copies files from the remote computer to the local computer.
    You should have already copied KB.pdf to the C:\Temp\Remote folder
  • Here is the command line:

Server Academy Members Only

Sorry, this lesson is only available to Server Academy Full Access members. Become a Full-Access Member now and you’ll get instant access to all of our courses.

0 0 votes
Lesson Rating
Notify of
profile avatar
Inline Feedbacks
View all comments