PowerShell: Remoting across HomeGroup machines

I’m a bit surprised I haven’t covered this before: I have no domain at home, but we are all part of the same HomeGroup. So with a little change from actions I take at work to remotely enable PowerShell, I can achieve it at home as well.

As a rule of thumb for these examples, when doing the admin actions to set these things up, always start the PowerShell session in administrator mode.

  1. Make sure winrm is running (apply these actions generally to all machines in the HomeGroup for simplicity, even though in some contexts we want to be the local machine, and in others the remote machine:

winrm quickconfig

PSRemoting06

It’s running, fine – just confirm how that looks in Services:

Get-Service WinRM

PSRemoting09

2. Enable PowerShell remoting (with Force option to override the interaction)

Enable-PSRemoting -Force

PSRemoting07

3. Add the remote computer to the list of trusted hosts for the local computer in WinRm:

winrm s winrm/config/client '@{TrustedHosts="The Remote PC"}'

PSRemoting08

4. Now try to connect to the remote PC

New-PSSession -ComputerName Remote-PC -Credential Get-Credential

PSRemoting10

5. Do something on the remote PC

A trivial example just to prove that we are doing stuff on the remote machine – the file in the screenshot below datagen.txt for example I know to exist only on the remote computer, not the local one:

function Do-It() {
 [CmdletBinding()]
 Param()

$session = New-PSSession -ComputerName Remote-PC
 Invoke-Command -Session $session -ScriptBlock {
 $VerbosePreference = $using:VerbosePreference
 Write-Verbose "Test"
 Get-ChildItem -Path c:\ -Filter *.txt
 }
 }

PSRemoting11

PSRemoting12

Advertisements

One thought on “PowerShell: Remoting across HomeGroup machines

  1. Pingback: PowerShell: more on remoting on a new-build | The Things I do

Leave a Reply

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

WordPress.com Logo

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

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s