Level 1
0 / 100 XP

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

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…