PowerShell Genie

New-PSSession

Use New-PSSession to open a persistent connection to a remote computer and return a session object.

Command 2 min read Windows PowerShell 5.1 and PowerShell 7

Documentation: Microsoft Learn — PowerShell module reference

Syntax

1PS> New-PSSession [[-ComputerName] <string[]>] [-Credential <PSCredential>] [-Name <String[]>] [-Port <Int32>] [-UseSSL] [-ConfigurationName <String>] [-SessionOption <PSSessionOption>] [-ThrottleLimit <Int32>] [<CommonParameters>]
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>]
  1. Stage 1New-PSSession-ComputerName -Credential -Name -Port -UseSSL -ConfigurationName -SessionOption -ThrottleLimit

    Try it

    Windows PowerShell

    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.

    Interactive simulation · fictional data

    Examples

    New-PSSession -ComputerName SRV01;

    1PS> $s = New-PSSession -ComputerName SRV01; Invoke-Command -Session $s -ScriptBlock { $x = 1 }
    Show reference output

    Sample output · fictional data, shaped like the real thing

    PSComputerName  Result
    --------------  ------
    SRV01           Operation completed

    New-PSSession -ComputerName SRV01

    1PS> New-PSSession -ComputerName SRV01 -UseSSL -Port 5986
    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

    1PS> Get-PSSession | Remove-PSSession # always clean up
    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

    PowerShell module reference on Microsoft Learn

    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.

    New-PSSession reference on Microsoft Learn

    Put this command to work

    Create a reusable remoting session

    Create $labSession with New-PSSession for lab-server.

    Review the lesson

    Recap

    New-PSSession Use New-PSSession to open a persistent connection to a remote computer and return a session object.

    Next: Enter-PSSession
    Genie guideNew-PSSession

    Use New-PSSession to open a persistent connection to a remote computer and return a session object. The console below is pre-loaded — run it, then change a value and run it again.