PowerShell Logo Small

Get-PSSession



This is the built-in help made by Microsoft for the command 'Get-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

Gets the Windows PowerShell sessions (PSSessions) in the current session.

SYNTAX


Get-PSSession [[-ComputerName] <string[]>] [<CommonParameters>]
Get-PSSession [-Id] <Int32[]> [<CommonParameters>]
Get-PSSession [-InstanceId <Guid[]>] [<CommonParameters>]
Get-PSSession [-Name <string[]>] [<CommonParameters>]



Search powershellhelp.space

DESCRIPTION


The Get-PSSession cmdlet gets the Windows PowerShell sessions (PSSessions) that were created in the current session.

Without parameters, Get-PSSession gets all of the PSSessions created in the current session. You can use the parameters of Get-PSSession to get t
he sessions that are connected to particular computers, or you can identify sessions by their names, IDs, or instance IDs.

For more information about Windows PowerShell sessions, see about_PSSessions.



<

RELATED LINKS

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

REMARKS

<

Examples


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

C:\PS>get-pssession



Description
-----------
This command gets all of the PSSessions that were created in the current session.

It does not get PSSessions that were created in other sessions or on other computers, even if they connect to this computer.








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

C:\PS>$s = get-pssession -computername Server02



Description
-----------
This command gets the PSSessions that are connected to the Server02 computer and saves them in the $p variable.








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

C:\PS>new-pssession -computername Server01, Server02, Server03

C:\PS> $s1, $s2, $s3 = get-pssession



Description
-----------
This example shows how to save the results of a Get-PSSession command in multiple variables.

The first command uses the New-PSSession cmdlet to create PSSessions on three remote computers.

The second command uses a Get-PSSession cmdlet to get the three PSSessions. It then saves each of the PSSessions in a separate variable.

When Windows PowerShell assigns an array of objects to an array of variables, it assigns the first object to the first variable, the second objec
t to the second variable, and so on. If there are more objects than variables, it assigns all remaining objects to the last variable in the array
. If there are more variables than objects, the extra variables are not used.








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

C:\PS>get-pssession | format-table -property computername, InstanceID

C:\PS> $s = get-pssession -InstanceID a786be29-a6bb-40da-80fb-782c67f7db0f

C:\PS> remove-pssession -session $s



Description
-----------
This example shows how to get a PSSession by using its instance ID, and then to delete the PSSession.

The first command gets all of the PSSessions on the local computer. It sends the PSSessions to the Format-Table cmdlet, which displays the Comput
erName and InstanceID properties of each PSSession.

The second command uses the Get-PSSession cmdlet to get a particular PSSession and to save it in the $s variable. The command uses the InstanceID
parameter to identify the PSSession.

The third command uses the Remove-PSSession cmdlet to delete the PSSession in the $s variable.








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

C:\PS>get-pssession -computername Serv*



Description
-----------
This command gets all the PSSessions that connect to computers that have computer names that begin with "Serv".








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

C:\PS>get-pssession -name Test*, Ux*



Description
-----------
This command gets PSSessions that have names that begin with "Test" or "Ux".








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

C:\PS>get-pssession 2



Description
-----------
This command gets the PSSession with ID 2.