CmdID

CmdID / PowerShell / Cmdlets / Get

Get-PSSession

Gets the PowerShell sessions on local and remote computers. PowerShell reference

From the PowerShell reference 19 parameters Alias gsn

Opens CmdID with your command, read as PowerShell. It is read in your browser and sent nowhere.

What it does

from the PowerShell reference, CC BY 4.0

Gets the PowerShell sessions on local and remote computers. The Get-PSSession cmdlet gets the user-managed PowerShell sessions (PSSessions) on local and remote computers. Starting in Windows PowerShell 3.0, sessions are stored on the computers at the remote end of each connection. You can use the ComputerName or ConnectionUri parameters of Get-PSSession to get the sessions that connect to the local computer or remote computers, even if they were not created in the current session. Without parameters, Get-PSSession gets all sessions that were created in the current session. Use the filtering parameters, including Name, Id, InstanceId, State, ApplicationName, and ConfigurationName to select from among the sessions that Get-PSSession returns. Use the remaining parameters to configure the temporary connection in which the Get-PSSession command runs when you use the ComputerName or ConnectionUri parameters. NOTE: In Windows PowerShell 2.0, without parameters, Get-PSSession gets all sessions that were created in the current session. The ComputerName parameter gets sessions that were created in the current session and connect to the specified computer. For more information about PowerShell sessions, see about_PSSessions.

Get-PSSession [-Name <String[]>] [<CommonParameters>]
Get-PSSession [-ComputerName] <String[]> [-ApplicationName <String>] [-ConfigurationName <String>] [-Name <String[]>] [-Credential <PSCredential>] [-Authentication <AuthenticationMechanism>] [-CertificateThumbprint <String>] [-Port <Int32>] [-UseSSL] [-ThrottleLimit <Int32>] [-State <SessionFilterState>] [-SessionOption <PSSessionOption>] [<CommonParameters>]
Get-PSSession [-ComputerName] <String[]> [-ApplicationName <String>] [-ConfigurationName <String>] -InstanceId <Guid[]> [-Credential <PSCredential>] [-Authentication <AuthenticationMechanism>] [-CertificateThumbprint <String>] [-Port <Int32>] [-UseSSL] [-ThrottleLimit <Int32>] [-State <SessionFilterState>] [-SessionOption <PSSessionOption>] [<CommonParameters>]
Get-PSSession [-ConnectionUri] <Uri[]> [-ConfigurationName <String>] [-AllowRedirection] -InstanceId <Guid[]> [-Credential <PSCredential>] [-Authentication <AuthenticationMechanism>] [-CertificateThumbprint <String>] [-ThrottleLimit <Int32>] [-State <SessionFilterState>] [-SessionOption <PSSessionOption>] [<CommonParameters>]
Get-PSSession [-ConnectionUri] <Uri[]> [-ConfigurationName <String>] [-AllowRedirection] [-Name <String[]>] [-Credential <PSCredential>] [-Authentication <AuthenticationMechanism>] [-CertificateThumbprint <String>] [-ThrottleLimit <Int32>] [-State <SessionFilterState>] [-SessionOption <PSSessionOption>] [<CommonParameters>]
Get-PSSession [-ConfigurationName <String>] [-Name <String[]>] [-State <SessionFilterState>] -ContainerId <String[]> [<CommonParameters>]
Get-PSSession [-ConfigurationName <String>] -InstanceId <Guid[]> [-State <SessionFilterState>] -ContainerId <String[]> [<CommonParameters>]
Get-PSSession [-ConfigurationName <String>] [-Name <String[]>] [-State <SessionFilterState>] -VMId <Guid[]> [<CommonParameters>]
Get-PSSession [-ConfigurationName <String>] -InstanceId <Guid[]> [-State <SessionFilterState>] -VMId <Guid[]> [<CommonParameters>]
Get-PSSession [-ConfigurationName <String>] [-Name <String[]>] [-State <SessionFilterState>] -VMName <String[]> [<CommonParameters>]
Get-PSSession [-ConfigurationName <String>] -InstanceId <Guid[]> [-State <SessionFilterState>] -VMName <String[]> [<CommonParameters>]
Get-PSSession [-InstanceId <Guid[]>] [<CommonParameters>]
Get-PSSession [-Id] <Int32[]> [<CommonParameters>]

Get sessions created in the current session

Get-PSSessionIdentify

Get sessions connected to the local computer

Get-PSSession -ComputerName "localhost"Identify

Get sessions connected to a computer

Get-PSSession -ComputerName "Server02"Identify

Save results of this command

New-PSSession -ComputerName Server01, Server02, Server03 $s1, $s2, $s3 = Get-PSSessionIdentify

Delete a session by using an instance ID

Get-PSSession | Format-Table -Property ComputerName, InstanceId $s = Get-PSSession -InstanceId a786be29-a6bb-40da-80fb-782c67f7db0f Remove-PSSession -Session $sIdentify

Get a session that has a particular name

Get-PSSession -ComputerName Server02, Server12 -Name BackupJob* -ConfigurationName ITTasks -SessionOption @{OperationTimeout=240000}Identify

Get a session by using its ID

Get-PSSession -Id 2Identify

Its page in the reference: Get-PSSession.

Parameters

19 in the PowerShell reference
Show its 19 parameters
-AllowRedirectionIndicates that this cmdlet allows redirection of this connection to an alternate Uniform Resource Identifier (URI). By default, PowerShell does not redirect connections. This parameter configures the temporary connection that is created to run a Get-PSSession command with the ConnectionUri parameter. This parameter was introduced in Windows PowerShell 3.0.
-ApplicationNameSpecifies the name of an application. This cmdlet connects only to sessions that use the specified application. Enter the application name segment of the connection URI. For example, in the following connection URI, the application name is WSMan: http://localhost:5985/WSMAN. The application name of a session is stored in the Runspace.ConnectionInfo.AppName property of the session. The value of this parameter is used to select and filter sessions. It does not change the application that the session uses.
-AuthenticationSpecifies the mechanism that is used to authenticate credentials for the session in which the Get-PSSession command runs. This parameter configures the temporary connection that is created to run a Get-PSSession command with the ComputerName or ConnectionUri parameter. The acceptable values for this parameter are: - Default - Basic - CredSSP - Digest - Kerberos - Negotiate - NegotiateWithImplicitCredential. The default value is Default. For more information about the values of this parameter, see AuthenticationMechanism Enumeration. CAUTION: Credential Security Support Provider (CredSSP) authentication, in which the user's credentials are passed to a remote computer to be authenticated, is designed for commands that require authentication on more than one resource, such as accessing a remote network share. This mechanism increases the security risk of the remote operation. If the remote computer is compromised, the credentials that are passed to it can be used to control the network session. This parameter was introduced in Windows PowerShell 3.0.
-CertificateThumbprintSpecifies the digital public key certificate (X509) of a user account that has permission to create the session in which the Get-PSSession command runs. Enter the certificate thumbprint of the certificate. This parameter configures the temporary connection that is created to run a Get-PSSession command with the ComputerName or ConnectionUri parameter. Certificates are used in client certificate-based authentication. They can be mapped only to local user accounts; they do not work with domain accounts. To get a certificate thumbprint, use a Get-Item or Get-ChildItem command in the PowerShell Cert: drive. This parameter was introduced in Windows PowerShell 3.0.
-ComputerNameSpecifies an array of names of computers. Gets the sessions that connect to the specified computers. Wildcard characters are not permitted. There is no default value. Beginning in Windows PowerShell 3.0, PSSession objects are stored on the computers at the remote end of each connection. To get the sessions on the specified computers, PowerShell creates a temporary connection to each computer and runs a Get-PSSession command. NOTE: This parameter gets sessions only from computers that run Windows PowerShell 3.0 or later versions of PowerShell. Earlier versions do not store sessions.
-ConfigurationNameSpecifies the name of a configuration. This cmdlet gets only to sessions that use the specified session configuration. Enter a configuration name or the fully qualified resource URI for a session configuration. If you specify only the configuration name, the following schema URI is prepended: http://schemas.microsoft.com/powershell. The configuration name of a session is stored in the ConfigurationName property of the session. The value of this parameter is used to select and filter sessions. It does not change the session configuration that the session uses. For more information about session configurations, see about_Session_Configurations.
-ConnectionUriSpecifies a URI that defines the connection endpoint for the temporary session in which the Get-PSSession command runs. The URI must be fully qualified. This parameter configures the temporary connection that is created to run a Get-PSSession command with the ConnectionUri parameter. The format of this string is: <Transport>://<ComputerName>:<Port>/<ApplicationName> The default value is: http://localhost:5985/WSMAN. If you do not specify a ConnectionUri, you can use the UseSSL, ComputerName, Port, and ApplicationName parameters to specify the ConnectionURI values. Valid values for the Transport segment of the URI are HTTP and HTTPS. If you specify a connection URI with a Transport segment, but do not specify a port, the session is created with standards ports: 80 for HTTP and 443 for HTTPS. To use the default ports for PowerShell remoting, specify port 5985 for HTTP or 5986 for HTTPS. If the destination computer redirects the connection to a different URI, PowerShell prevents the redirection unless you use the AllowRedirection parameter in the command. This parameter was introduced in Windows PowerShell 3.0. …
-ContainerIdSpecifies an array of IDs of containers. This cmdlet starts an interactive session with each of the specified containers. Use the docker ps command to get a list of container IDs. For more information, see the help for the docker ps command.
-CredentialSpecifies a user credential. This cmdlet runs the command with the permissions of the specified user. Specify a user account that has permission to connect to the remote computer and run a Get-PSSession command. The default is the current user. Credentials are stored in a PSCredential object and the password is stored as a SecureString. NOTE: For more information about SecureString data protection, see How secure is SecureString?. This parameter configures to the temporary connection that is created to run a Get-PSSession command with the ComputerName or ConnectionUri parameter. This parameter was introduced in Windows PowerShell 3.0.
-IdSpecifies an array of session IDs. This cmdlet gets only the sessions with the specified IDs. Type one or more IDs, separated by commas, or use the range operator (..) to specify a range of IDs. You cannot use the Id parameter together with the ComputerName parameter. An ID is an integer that uniquely identifies the user-managed sessions in the current session. It is easier to remember and type than the InstanceId, but it is unique only within the current session. The ID of a session is stored in the Id property of the session.
-InstanceIdSpecifies an array of instance IDs of sessions. This cmdlet gets only the sessions with the specified instance IDs. The instance ID is a GUID that uniquely identifies a session on a local or remote computer. The InstanceId is unique, even when you have multiple sessions running in PowerShell. The instance ID of a session is stored in the InstanceId property of the session.
-NameSpecifies an array of session names. This cmdlet gets only the sessions that have the specified friendly names. Wildcard characters are permitted. The friendly name of a session is stored in the Name property of the session.
-PortSpecifies the specified network port that is used for the temporary connection in which the Get-PSSession command runs. To connect to a remote computer, the remote computer must be listening on the port that the connection uses. The default ports are 5985, which is the WinRM port for HTTP, and 5986, which is the WinRM port for HTTPS. Before using an alternate port, you must configure the WinRM listener on the remote computer to listen at that port. To configure the listener, type the following two commands at the PowerShell prompt: Remove-Item -Path WSMan:\Localhost\listener\listener* -Recurse New-Item -Path WSMan:\Localhost\listener -Transport http -Address * -Port <port-number> This parameter configures to the temporary connection that is created to run a Get-PSSession command with the ComputerName or ConnectionUri parameter. Do not use the Port parameter unless you must. The Port set in the command applies to all computers or sessions on which the command runs. An alternate port setting might prevent the command from running on all computers. This parameter was introduced in Windows PowerShell 3.0.
-SessionOptionSpecifies advanced options for the session. Enter a SessionOption object, such as one that you create by using the New-PSSessionOption cmdlet, or a hash table in which the keys are session option names and the values are session option values. The default values for the options are determined by the value of the $PSSessionOption preference variable, if it is set. Otherwise, the default values are established by options set in the session configuration. The session option values take precedence over default values for sessions set in the $PSSessionOption preference variable and in the session configuration. However, they do not take precedence over maximum values, quotas or limits set in the session configuration. For a description of the session options, including the default values, see New-PSSessionOption. For information about the $PSSessionOption preference variable, see about_Preference_Variables. For more information about session configurations, see about_Session_Configurations.
-StateSpecifies a session state. This cmdlet gets only sessions in the specified state. The acceptable values for this parameter are: All, Opened, Disconnected, Closed, and Broken. The default value is All. The session state value is relative to the current sessions. Sessions that were not created in the current sessions and are not connected to the current session have a state of Disconnected even when they are connected to a different session. The state of a session is stored in the State property of the session. This parameter was introduced in Windows PowerShell 3.0.
-ThrottleLimitSpecifies the maximum number of concurrent connections that can be established to run the Get-PSSession command. If you omit this parameter or enter a value of 0 (zero), the default value, 32, is used. The throttle limit applies only to the current command, not to the session or to the computer. This parameter was introduced in Windows PowerShell 3.0.
-UseSSLIndicates that this cmdlet uses the Secure Sockets Layer (SSL) protocol to establish the connection in which the Get-PSSession command runs. By default, SSL is not used. If you use this parameter, but SSL is not available on the port used for the command, the command fails. This parameter configures the temporary connection that is created to run a Get-PSSession command with the ComputerName parameter. This parameter was introduced in Windows PowerShell 3.0.
-VMIdSpecifies an array of ID of virtual machines. This cmdlet starts an interactive session with each of the specified virtual machines. To see the virtual machines that are available to you, use the following command: Get-VM | Select-Object -Property Name, ID
-VMNameSpecifies an array of names of virtual machines. This cmdlet starts an interactive session with each of the specified virtual machines. To see the virtual machines that are available to you, use the Get-VM cmdlet.