New-PSSession
Use New-PSSession to open a persistent connection to a remote computer and return a session object.
Documentation: Microsoft Learn — PowerShell module reference
Syntax
See the command anatomy
Read the command and its supplied arguments. This example requires real PowerShell or its module; this diagram does not execute it.
New-PSSession [[-ComputerName] <string[]>] [-Credential <PSCredential>] [-Name <String[]>] [-Port <Int32>] [-UseSSL] [-ConfigurationName <String>] [-SessionOption <PSSessionOption>] [-ThrottleLimit <Int32>] [<CommonParameters>]- Stage 1New-PSSession
-ComputerName -Credential -Name -Port -UseSSL -ConfigurationName -SessionOption -ThrottleLimit
Try it
PowerShell example · browser support is limited.
Execution scope: The full example below requires PowerShell outside this browser. You can edit this runner to use the supported practice commands; unsupported syntax returns an explanation.
Follow the objects
Run the command to inspect each stage.
Examples
New-PSSession -ComputerName SRV01;
Show reference output
Sample output · fictional data, shaped like the real thing
PSComputerName Result -------------- ------ SRV01 Operation completed
New-PSSession -ComputerName SRV01
Show reference output
Sample output · fictional data, shaped like the real thing
Id Name ComputerName State ConfigurationName -- ---- ------------ ----- ----------------- 1 Session1 SRV01 Opened Microsoft.PowerShell
List all with Get-PSSession
Show reference output
Sample output · fictional data, shaped like the real thing
Id ComputerName State Availability -- ------------ ------ ------------ 1 SRV01 Opened Available
Parameters
Parameter definitions:
-ComputerName-Credential-Name-Port-UseSSL-ConfigurationName-SessionOption-ThrottleLimit
Practical use and troubleshooting
Practical scenario: Use New-PSSession when you need to open a persistent connection to a remote computer and return a session object. Start with one identified target and inspect the returned values before extending the operation to a list. Keep the identity in your report so you can trace each result back to the object or path that produced it.
Common error and fix: A remoting transport error needs checking WinRM or the selected transport, authentication and endpoint configuration. Verify the computer name and connection independently before running a batch of remote commands. In an unattended script, capture this failure with its original error record and record which target failed. An empty result and an unsuccessful query must remain distinguishable in the final report.
See also: Enter-PSSession. New-PSSession creates a reusable remoting session for automation; Enter-PSSession opens an interactive session. Interactive entry does not replace a pipeline-friendly Invoke-Command workflow. Read the linked command before substituting it; similar names do not imply identical inputs or output.
Put this command to work
Create a reusable remoting session
Create $labSession with New-PSSession for lab-server.
The sandbox is visible now. Sign in with Google only when you run or check a task; commands and temporary files are discarded when you leave.
Run a command to inspect its result.
Inspect starting data
Supported syntax
Virtual files
Recap
New-PSSession Use New-PSSession to open a persistent connection to a remote computer and return a session object.
Next: Enter-PSSession