New-PSSession is a powerful PowerShell command that enables users to create a persistent connection to a remote computer. This command is used to establish a secure connection between a local computer and a remote computer, allowing users to execute commands on the remote computer and access its resources. In this guide, we will explore the syntax, parameters, inputs, outputs, examples, and tips for using the New-PSSession command.
Syntax
The syntax for the New-PSSession command is as follows:
New-PSSession [-ComputerName] <String[]> [-ApplicationName <String>] [-Authentication <AuthenticationMechanism>] [-CertificateThumbprint <String>] [-ConfigurationName <String>] [-Credential <PSCredential>] [-EnableNetworkAccess] [-LoadUserProfile] [-Name <String>] [-Port <Int32>] [-SessionOption <PSSessionOption>] [-UseSSL] [-ThrottleLimit <Int32>] [-ProxyAccessType <ProxyAccessType>] [-ProxyAuthentication <ProxyAuthenticationMechanism>] [-ProxyCredential <PSCredential>] [-ProxyPort <Int32>] [-ProxyServer <String>] [-AllowRedirection] [-OutputBufferingMode <OutputBufferingMode>] [-NoMachineProfile] [-NoEncryption] [-InputObject <PSObject>] [-AsJob] [-WhatIf] [-Confirm] [<CommonParameters>]
Parameters
The New-PSSession command has several parameters that can be used to customize the connection. These parameters include:
ComputerName | Specifies the name of the remote computer to which the connection is established. |
ApplicationName | Specifies the name of the application that is used to create the session. |
Authentication | Specifies the authentication mechanism used to authenticate the user. |
CertificateThumbprint | Specifies the thumbprint of the certificate used to authenticate the user. |
ConfigurationName | Specifies the name of the configuration that is used to create the session. |
Credential | Specifies the credentials used to authenticate the user. |
EnableNetworkAccess | Specifies whether the session is allowed to access the network. |
LoadUserProfile | Specifies whether the user profile is loaded when the session is created. |
Name | Specifies the name of the session. |
Port | Specifies the port number used to establish the connection. |
SessionOption | Specifies the session options used to create the session. |
UseSSL | Specifies whether the connection is secured using SSL. |
ThrottleLimit | Specifies the maximum number of concurrent connections. |
ProxyAccessType | Specifies the type of proxy used to establish the connection. |
ProxyAuthentication | Specifies the authentication mechanism used to authenticate the proxy. |
ProxyCredential | Specifies the credentials used to authenticate the proxy. |
ProxyPort | Specifies the port number used to establish the connection through the proxy. |
ProxyServer | Specifies the name of the proxy server used to establish the connection. |
AllowRedirection | Specifies whether the connection can be redirected to another computer. |
OutputBufferingMode | Specifies the output buffering mode used for the session. |
NoMachineProfile | Specifies whether the machine profile is loaded when the session is created. |
NoEncryption | Specifies whether the connection is encrypted. |
InputObject | Specifies the object to be used to create the session. |
AsJob | Specifies whether the command is run as a background job. |
WhatIf | Specifies whether the command will be simulated without actually being executed. |
Confirm | Specifies whether the user will be prompted for confirmation before executing the command. |
Inputs
The New-PSSession command accepts several inputs, including the ComputerName, ApplicationName, Authentication, CertificateThumbprint, ConfigurationName, Credential, EnableNetworkAccess, LoadUserProfile, Name, Port, SessionOption, UseSSL, ThrottleLimit, ProxyAccessType, ProxyAuthentication, ProxyCredential, ProxyPort, ProxyServer, AllowRedirection, OutputBufferingMode, NoMachineProfile, NoEncryption, InputObject, AsJob, WhatIf, and Confirm parameters.
Outputs
The New-PSSession command produces a PSSession object that contains information about the session, including the session ID, computer name, user name, authentication type, and session state.
Examples
The following example creates a session to a remote computer named “Server1”:
New-PSSession -ComputerName Server1
The following example creates a session to a remote computer named “Server1” and loads the user profile:
New-PSSession -ComputerName Server1 -LoadUserProfile
The following example creates a session to a remote computer named “Server1” and uses the credentials of the user “User1”:
New-PSSession -ComputerName Server1 -Credential User1
Tips
When