PowerShell Genie

PowerShell Remoting

Separate where a command runs from how its results are returned.

Lesson 2 min read Windows PowerShell 5.1 and PowerShell 7

Documentation: Microsoft Learn

Overview

PowerShell remoting runs commands in another session. Invoke-Command -ComputerName typically uses WSMan; SSH remoting uses different connection parameters and setup. A successful network connection does not by itself establish permission to use the PowerShell endpoint.

The example below is a plan: it creates one local object per server with a command stored as a string. It does not open a session or run Get-Service remotely. Use it to inspect the target list before writing an execution step.

For actual work, decide whether you need a one-time invocation or a reusable PSSession. Variables in the local session are not automatically variables in the remote session. Pass arguments or use the supported using scope syntax deliberately.

Returned objects may be deserialized snapshots with properties but without their original methods. Also, a remote server accessing a third server introduces a separate credential-delegation problem. Do not widen a file ACL merely because a second-hop request failed.

Inspect this example’s structure

Read the command and its supplied arguments. This example requires real PowerShell or its module; this diagram does not execute it.

$servers = 'WEB01' , 'WEB02' , 'SQL01' foreach ($s in $servers) { [pscustomobject]@{ ComputerName = $s Command = 'Get-Service -Name Spooler' } }
  1. Stage 1$serversPositional values or no named parameters

    What happens

    The three rows identify intended targets; they contain no service state. Before real execution, test one authorized target, capture its identity and inspect the returned properties. A row listing a command is not evidence that it succeeded.

    Worth remembering

    Verify target, endpoint permission, returned data and any second-hop requirement separately.

    Primary documentation

    Microsoft Learn: remote

    Try it

    Illustrative output · values vary by environment

    1PS> $servers = 'WEB01' , 'WEB02' , 'SQL01'
    2PS> foreach ($s in $servers) {
    3PS> [pscustomobject]@{
    4PS> ComputerName = $s
    5PS> Command = 'Get-Service -Name Spooler'
    6PS> } }

    Example reader

    Inspect this page's example

    Fictional browser data when supported

    Run supported commands against the practice data, or inspect the example without executing it.

    Ready to inspect.

      Shows the per-server result shape without making a network call.

      Show reference output

      Illustrative output · values vary by environment

      ComputerName Command
      ------------ -------
      WEB01        Get-Service -Name Spooler
      WEB02        Get-Service -Name Spooler
      SQL01        Get-Service -Name Spooler

      Practise this

      Read remote services

      Read all service records from fictional lab-server. Use Invoke-Command -ComputerName lab-server -ScriptBlock. No network is contacted.

      Review the lesson

      Keep going

      Next: PowerShell WinRM
      Genie guidePowerShell Remoting

      Separate where a command runs from how its results are returned.