Windows Remoting

Remoting allows you to log into the command line of the target machine. It is similar to the SSH command on Linux, in that it provides access only to the command line.

It has to be set up on beforehand by using PowerShell with Admin privileges on both the controlled and controlling machine.

Note:  You will eventually need to the name of your machine. You can find this out with the following command:

Get-ChildItem env:ComputerName

Here are the steps to set it up:  At the PowerShell prompt on each machine

1. Turn on PSRemoting.

PS> Enable-PSRemoting  -Force  # The Force parameter eliminates a lot of annoying questions.

2. For machines that are not on a domain-based nework, you need to configure the trusted hosts lists on each machine.

PS> Set-Item wsman:localhostclienttrustedhosts *

This allows any computer to connect to this machine.  If you want to restrict the trusted hosts, you can use a comma-separated list of IP addresses, or computer names.

3. Restart the WinRM service

PS> Restart-Service WinRM

Repeat the three steps above for any machine that you wish to access via Remoting.

To test the connection:

Note:  You will eventually need to the name of your machine. You can find this out with the following command:  Get-ChildItem env:ComputerName

Test-WsMan <computename>

If the connection is made you’ll get a reply…if not then the connection will appear to hang at the prompt.

Now for the real deal:

To execute a single command from the source machine on the target machine.

Invoke-Command -ComputerName <computername> -ScriptBlock {command } -credential <username>

The credential paraeter will put up a name-password gui box to get your user credentials.

You can start an entire remote session with a similar command

Enter-PSSession -ComputerName <computer> – Credential <username>

This will give you a command line prefaced with the computer name.

[Win7VM] PS >

You can run commands that reside only on the remote computer….or run PS commands on your own computer that execute on the remote computer.

To return to your own machine:

[Win7VM] PS> Exit

Because Remoting runs as a service, you don’t have to have PowerShell open on the remote machine to be able to connect to it.

If you set this up first using a Virtualbox virtual machine, you can see how both ends of the connection work without inconveniencing a user.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s