PowerShell Logo Small

New-PSSession



This is the built-in help made by Microsoft for the command 'New-PSSession', in PowerShell version 2 - as retrieved from Windows version 'Microsoft® Windows Vista™ Ultimate ' PowerShell help files on 2016-06-23.

For PowerShell version 3 and up, where you have Update-Help, this command was run just before creating the web pages from the help files.

SYNOPSIS

Creates a persistent connection to a local or remote computer.

SYNTAX


New-PSSession [[-ComputerName] <string[]>] [-ApplicationName <string>] [-Authentication {Default | Basic | Negotiate | NegotiateWithImplicitCrede
ntial | Credssp | Digest | Kerberos}] [-CertificateThumbprint <string>] [-ConfigurationName <string>] [-Credential <PSCredential>] [-Name <string
[]>] [-Port <int>] [-SessionOption <PSSessionOption>] [-UseSSL] [-ThrottleLimit <int>] [<CommonParameters>]
New-PSSession [[-Session] <PSSession[]>] [-Name <string[]>] [-ThrottleLimit <int>] [<CommonParameters>]
New-PSSession [-ConnectionURI] <Uri[]> [-AllowRedirection] [-Authentication {Default | Basic | Negotiate | NegotiateWithImplicitCredential | Cred
ssp | Digest | Kerberos}] [-CertificateThumbprint <string>] [-ConfigurationName <string>] [-Credential <PSCredential>] [-Name <string[]>] [-Sessi
onOption <PSSessionOption>] [-ThrottleLimit <int>] [<CommonParameters>]



Search powershellhelp.space

DESCRIPTION


The New-PSSession cmdlet creates a Windows PowerShell session (PSSession) on a local or remote computer. When you create a PSSession, Windows Po
werShell establishes a persistent connection to the remote computer.

Use a PSSession to run multiple commands that share data, such as a function or the value of a variable. To run commands in a PSSession, use the
Invoke-Command cmdlet. To use the PSSession to interact directly with a remote computer, use the Enter-PSSession cmdlet. For more information, se
e about_PSSessions.

You can run commands on a remote computer without creating a PSSession by using the ComputerName parameters of Enter-PSSession or Invoke-Command.
When you use the ComputerName parameter, Windows PowerShell creates a temporary connection that is used for the interactive session or for a sin
gle command and is then closed.



<

RELATED LINKS

Online version: http://go.microsoft.com/fwlink/?LinkID=135237
about_PSSessions
about_Remote
Get-PSSession
Remove-PSSession
Enter-PSSession
Exit-PSSession
Invoke-Command

REMARKS

<

Examples


-------------------------- EXAMPLE 1 --------------------------

C:\PS>$s = new-pssession



Description
-----------
This command creates a new PSSession on the local computer and saves the PSSession in the $s variable.

You can now use this PSSession to run commands on the local computer.








-------------------------- EXAMPLE 2 --------------------------

C:\PS>$Server01 = new-pssession -ComputerName Server01



Description
-----------
This command creates a new PSSession on the Server01 computer and saves it in the $Server01 variable.

When creating multiple PSSessions, assign them to variables with useful names. This will help you manage the PSSessions in subsequent commands.








-------------------------- EXAMPLE 3 --------------------------

C:\PS>$s1, $s2, $s3 = new-session -computername server1,server2,server3



Description
-----------
This command creates three new PSSessions, one on each of the computers specified by the ComputerName parameter.

The command uses the assignment operator (=) to assign the new PSSessions to an array of variables: $s1, $s2, $s3. It assigns the Server01 PSSess
ion to $s1, the Server02 PSSession to $s2, and the Server03 PSSession to $s3.

When you assign multiple objects to an array of variables, Windows PowerShell assigns each object to a variable in the array respectively. If the
re are more objects than variables, all remaining objects are assigned to the last variable. If there are more variables than objects, the remain
ing variables are empty (null).








-------------------------- EXAMPLE 4 --------------------------

C:\PS>new-pssession -computername Server01 -port 8081 -useSSL -ConfigurationName E12



Description
-----------
This command creates a new PSSession on the Server01 computer that connects to server port 8081 and uses the SSL protocol. The new PSSession uses
an alternate session configuration called "E12".

Before setting the port, you must configure the WinRM listener on the remote computer to listen on port 8081. For more information, see the descr
iption of the Port parameter.








-------------------------- EXAMPLE 5 --------------------------

C:\PS>new-pssession -session $s -credential domain01\user01



Description
-----------
This command creates a new PSSession with the same properties as an existing PSSession. You can use this command format when the resources of an
existing PSSession are exhausted and a new PSSession is needed to offload some of the demand.

The command uses the Session parameter of New-PSSession to specify the PSSession saved in the $s variable. It uses the credentials of the Domain1
\Admin01 user to complete the command.








-------------------------- EXAMPLE 6 --------------------------

C:\PS>$global:s = new-pssession -computername server1.domain44.corpnet.fabrikam.com -credential domain01\admin01



Description
-----------
This example shows how to create a PSSession with a global scope on a computer in a different domain.

By default, PSSessions created at the command line are created with local scope and PSSessions created in a script have script scope.

To create a PSSession with global scope, create a new PSSession and then store the PSSession in a variable that is cast to a global scope. In thi
s case, the $s variable is cast to a global scope.

The command uses the ComputerName parameter to specify the remote computer. Because the computer is in a different domain than the user account,
the full name of the computer is specified along with the credentials of the user.








-------------------------- EXAMPLE 7 --------------------------

C:\PS>$rs = get-content c:\test\servers.txt | new-PSsession -throttleLimit 50



Description
-----------
This command creates a PSSession on each of the 200 computers listed in the Servers.txt file and it stores the resulting PSSession in the $rs var
iable. The PSSessions have a throttle limit of 50.

You can use this command format when the names of computers are stored in a database, spreadsheet, text file, or other text-convertible format.








-------------------------- EXAMPLE 8 --------------------------

C:\PS>$s = new-PSSession -URI http://Server01:91/NewSession -credential domain01\user01



Description
-----------
This command creates a PSSession on the Server01 computer and stores it in the $s variable. It uses the URI parameter to specify the transport pr
otocol, the remote computer, the port, and an alternate session configuration. It also uses the Credential parameter to specify a user account wi
th permission to create a session on the remote computer.








-------------------------- EXAMPLE 9 --------------------------

C:\PS>$s = new-PSSession -computername (import-csv servers.csv) -credential domain01\admin01 -throttlelimit 16

C:\PS> invoke-command -session $s -scriptblock {get-process powershell} -AsJob



Description
-----------
These commands create a set of PSSessions and then run a background job in each of the PSSessions.

The first command creates a new PSSession on each of the computers listed in the Servers.csv file. It uses the New-PSSession cmdlet to create the
PSSession. The value of the ComputerName parameter is a command that uses the Import-Csv cmdlet to import the Servers.csv file and read its cont
ents.

The command uses the Credential parameter to create the PSSessions with the permission of a domain administrator, and it uses the ThrottleLimit p
arameter to limit the command to 16 concurrent connections. The command saves the PSSessions in the $s variable.

The second command uses the AsJob parameter of Invoke-Command to start a background job that runs a "Get-Process PowerShell" command in each of t
he PSSessions in $s.

For more information about background jobs, see about_Jobs and about_Remote_Jobs.








-------------------------- EXAMPLE 10 --------------------------

C:\PS>new-PSSession -ConnectionURI https://management.exchangelabs.com/Management



Description
-----------
This command creates a new PSSession that connects to a computer that is specified by a URI instead of a computer name.








-------------------------- EXAMPLE 11 --------------------------

C:\PS>$so = New-WSManSessionOption -SkipCACheck

PS C:\> new-pssession -ConnectionUri https://management.exchangelabs.com/Management -SessionOption $so -credential server01\admin01



Description
-----------
This example shows how to create and use a SessionOption parameter.

The first command uses the New-WSManSessionOption cmdlet to create a session option. It saves the resulting SessionOption object in the $so param
eter.

The second command uses the option in a new session. The command uses the New-PSSession cmdlet to create a new session. The value of the SessionO
ption parameter is the SessionOption object in the $so variable.