PS Sessions
When Enter-PSSession and Invoke-Command were used with the ComputerName parameter, a PSSession was implicitly created and destroyed for each remote computer.
Creating the session outside of Invoke-Command is less convenient but allows sessions to be reused and offers greater control of the session lifespan.
New-PSSession and Get-PSSession
Sessions are created using the New-PSSession command. In the following example, a session is created on a computer named PSTEST:
PS> New-PSSession -ComputerName PSTEST
Id Name ComputerName State ConfigurationName Availability
-- ---- ------------ ----- ----------------- -----------
1 Session1 PSTEST Opened Microsoft.PowerShell Available
Sessions created using New-PSSession persist until the PSSession is removed (by Remove-PSSession) or the PowerShell session ends.
The following example returns sessions created in the current PowerShell session:
PS> Get-PSSession | Select-Object...