Reuse Remote Connections With New-PSSession
Create a persistent session and run multiple commands over it.
01Command
$ $s = New-PSSession -ComputerName server01; Invoke-Command -Session $s -ScriptBlock { Get-Date }; Remove-PSSession $s02What 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
04Undo
✓No undo needed — this command does not change persistent state.
05Sources
- New-PSSessionEvidence: Creates a persistent connection to a local or remote computer.
Last verified: 2026-10-13 · Category: System & Settings
06Related solutions
The nuclear option for broken connectivity: rebuild Winsock and the TCP/IP stack to defaults when adapters show 'no internet' despite everything else working.
A built-in PowerShell one-liner that answers 'is port 5432/3389/443 actually open through this network?' — no telnet client needed.
Configure a fixed IPv4 address, subnet mask and default gateway on any adapter in one line — essential for headless servers and remote workstations.