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