Skip to content

Running a PowerShell command on a remote machine — by Michael Taylor on Microsoft Q&A

intermediateforumLink only (©)

An accepted answer to how to run a locally-working command on other computers. It says to enable PowerShell remoting on the target first (on by default on servers, not on clients, and a security consideration), allow it through the firewall if not on a domain, then create a session with New-PSSession and run the script block with Invoke-Command.

Quick steps

  1. Enable remoting on the target machine
  2. Create a session with New-PSSession -ComputerName (add -Credential if needed)
  3. Run the code with Invoke-Command -Session $session -ScriptBlock { ... }

Paraphrased from the source. Menus can differ by version, so check the original for full details.

Read the full thread on learn.microsoft.com

Source: Running a PowerShell command on a remote machine by Michael Taylor on Microsoft Q&A. Licence: Link only (©).

Source reviewed
2026-11-02
Link checked
2026-11-02
Tested hands-on
Not by Oddbyte.Me

powershellremotingnew-pssessioninvoke-command

More in PowerShell

about_Execution_Policies — by Microsoft Learn

beginnerpage

Explains what PowerShell execution policies are, the available levels (Restricted, RemoteSigned, AllSigned, Bypass and others) and the scopes they apply to. It also stresses the policy is a safety net rather than a security boundary, and shows how to check and change it per user, machine or session. Loosening it (for example Unrestricted or Bypass) reduces protection, so prefer the narrowest scope.

Invok-Command on localhost not working — by Limitless Technology on Microsoft Q&A

intermediateforum

A user got Access denied running Invoke-Command against localhost even though WinRM was started. The answer explains Invoke-Command needs PowerShell remoting enabled even for the local machine, and suggests setting WinRM to Automatic, starting it and enabling remoting. The answer writes the cmdlet as EnablePSRemoting; the real name is Enable-PSRemoting. Enabling remoting opens a WinRM listener, so only do it where you need it.

PowerShell Remoting FAQ — by Microsoft Learn

intermediatepage

Question-and-answer guide to running PowerShell commands on other computers: how remoting works over WS-Management, Invoke-Command versus a persistent PSSession, throttling, serialized output and profiles not loading in remote sessions. It also covers workgroup and cross-domain caveats such as TrustedHosts, and remoting over SSH.