Reuse Remote Connections With New-PSSession

Create a persistent session and run multiple commands over it.

WindowsnetworksystemperformanceadminpowershellLow risk
Run $s = New-PSSession -ComputerName host, then pass -Session $s to each command.

01Command

Command
$ $s = New-PSSession -ComputerName server01; Invoke-Command -Session $s -ScriptBlock { Get-Date }; Remove-PSSession $s

02What it does

Each Invoke-Command normally opens and closes a connection, but a named PSSession is established once and reused, which reduces authentication overhead and preserves state such as imported modules. Persistent sessions are essential when automating several steps against the same host.

03Risk

RiskLow risk
RequirementsWindows 10/11 with PowerShell 5.1 or PowerShell 7+
!Warning: Idle sessions hold resources on both ends; close them with Remove-PSSession when the script finishes.

04Undo

✓No undo needed — this command does not change persistent state.

05Sources

  • New-PSSession
    Microsoft Learn · vendor-doc · 2026-09-20
    Evidence: Creates a persistent connection to a local or remote computer.

Last verified: 2026-10-13 · Category: System & Settings

06Related solutions