Get-PSSession - PowerShell command help and examples

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


NAME
Get-PSSession
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>]
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 the 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.
PARAMETERS
-ComputerName <string[]> Gets only the PSSessions that are connected to the specified computers. Wildcards are permitted. Type the NetBIOS name, an IP address, or a fully-qualified domain name of one or more computers. To specify the local computer, type the computer name, "localhost", or a dot (.). Required? false Position? 1 Default value Accept pipeline input? true (ByPropertyName) Accept wildcard characters? true -Id <Int32[]> Gets only the PSSessions with the specified IDs. Type one or more IDs (separated by commas), or use the range operator (..) to specify a range of IDs. An ID is an integer that uniquely identifies the PSSession in the current session. It is easier to remember and type than the InstanceId, but it is unique only within the current session. To find the ID of a PSSession, use Get-PSSession without parameters. Required? true Position? 1 Default value All sessions in the shell Accept pipeline input? true (ByPropertyName) Accept wildcard characters? false -InstanceId <Guid[]> Gets only the PSSessions with the specified instance IDs. The instance ID is a GUID that uniquely identifies a PSSession on a local or remote computer. The InstanceID is unique, even when you have multiple sessions running in Windows PowerShell. The InstanceID is stored in the InstanceID property of the object that represents a PSSession. To find the InstanceID of the PSSessions in the current session, type "get-pssession | format-table Name, ComputerName, InstanceId". Required? false Position? named Default value Accept pipeline input? true (ByPropertyName) Accept wildcard characters? true -Name <string[]> Gets only the PSSessions with the specified friendly names. Wildcards are permitted. To find the names of the PSSessions in the current session, type "get-pssession" without parameters. Required? false Position? named Default value Accept pipeline input? true (ByPropertyName) Accept wildcard characters? true <CommonParameters> This cmdlet supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction, WarningVariable, OutBuffer and OutVariable. For more information, type, "get-help about_commonparameters".
INPUTS
None You cannot pipe input to this cmdlet.
OUTPUTS
System.Management.Automation.Runspaces.PSSession Get-PSSession returns a PSSession object for each PSSession that it gets.
NOTES
Get-PSSession gets the PSSessions that were created in the current session. It does not get the session that is created when you open Windows PowerShell, and it does not get PSSessions that were created in other sessions or on other computers, even if they connect to the local computer.

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 object 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 ComputerName 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. 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 C:\Windows>powershell get-help Remove-PSSession -full

Microsoft Windows [Version 10.0.19045.3693]
Copyright (c) 2023 Microsoft Corporation.

ColorConsole [Version 3.7.1000] PowerShell 2.0-Export

Windows 11, 10, 8.1, 8, 7 / Server 2022, 2019, 2016











Windows-10


... Windows 10 FAQ
... Windows 10 How To


Windows 10 How To


... Windows 11 How To
... Windows 10 FAQ



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

HTTP: ... PS_Windows/en/Get-PSSession.htm
0.077
16567
Was ist der DNS-Cache unter Windows?
Windows 8.1 or 10 to Extend test period in or delay activation tool!
Show My-Computer and Control Panel on Desktop in Windows 11 and 10?
Windows 10/8.1: Can I disable or remove the lock screen  (faster login)?
Run directly minimized to tray excluding to see the main window?
Wo kann ich den Sendungsstatus von hermes.de oder DHL.de abfragen?
Why another countdown APP for Android and Windows?
Mehrere Dateien gleichzeitig umbenennen. Geht das in Windows?
Can I rename the This-PC in My-Computer on Windows 10?
Einige Webseiten verwenden schreckliche Farben. Kann man es abstellen?



(0)