How to run a PowerShell script on multiple remote computers

You have a script that works on your own PC. Now it has to run on 20 others. Here are the four common ways to do it, what each one needs, and where each one stops working.

Updated · 7 min read

Short answer: inside one office network with a domain, Invoke-Command (PowerShell Remoting) is built in and free. Once PCs sit in different networks, at home or behind NAT, an agent that connects out to a cloud panel is the option that keeps working without a VPN or open ports.

1. PowerShell Remoting (WinRM) with Invoke-Command

PowerShell Remoting is part of Windows. You enable it on every target PC once, then run a script block on many machines in parallel from your own PC:

# Once, on each target PC, in an elevated PowerShell
Enable-PSRemoting -Force

# From your admin PC
Invoke-Command -ComputerName PC-01, PC-02, PC-03 -ScriptBlock {
    Get-Service Spooler | Select-Object Status, Name
}

To run a script file instead of a block, use -FilePath C:\Scripts\cleanup.ps1. Results come back as objects, each tagged with PSComputerName.

What it needs

Where it breaks: laptops at home, branch offices without a VPN, PCs that are not in the domain.

2. PsExec

PsExec from Microsoft Sysinternals starts a process on a remote PC over SMB:

psexec \\PC-01 -s powershell -NoProfile -Command "Get-Volume"

3. Remote desktop, one PC at a time

Connect with RDP, TeamViewer, AnyDesk or similar, open PowerShell, paste the script. It works for one machine. For 20 machines it is an afternoon, it interrupts the user, and nothing records what ran where.

4. An agent on every PC (RMM)

A small service on each PC keeps an outbound connection to a central panel. Because the PC connects out, there are no inbound ports to open and no VPN to maintain; it works the same in the office, at home or on hotel Wi-Fi. This is how RMM (remote monitoring and management) tools work, including CtrlSoft.

Running a script with CtrlSoft

  1. Install the agent on each PC — by hand, or silently on many PCs with one command.
  2. Open Scripts, save your PowerShell or CMD script once.
  3. Run it on a device now, or create a schedule for one device or the whole group.
  4. Read the output and exit code of every run in the script's history. For a quick one-off command, use the command console on the device page.
Scripts run under the agent's Windows service account (Local System), not as the signed-in user. Use machine-wide paths such as $env:ProgramData or HKLM: rather than $env:USERPROFILE or HKCU:.

Comparison

MethodNeedsOutside the office networkMany PCs at once
Invoke-CommandWinRM, ports 5985/5986, domain or TrustedHostsOnly with a VPNYes
PsExecSMB 445, ADMIN$ share, admin accountOnly with a VPNWith your own loop
Remote desktopA remote-desktop tool and the user's timeDepends on the toolNo
Agent / RMMAgent installed once, outbound HTTPSYesYes, with output history

Tips that save you a rollback

Try it on your own PCs

Free for 30 days on up to 5 devices. No card, no server, no VPN.

Start 30-day free trial