Closes one or more Windows PowerShell sessions (PSSessions). (Remove-PSSession)

   

# NAME
Remove-PSSession

# SYNOPSIS
Closes one or more Windows PowerShell sessions (PSSessions).

# SYNTAX
Remove-PSSession [[-ComputerName] <string[]>] [-Confirm] [-WhatIf] [<CommonParameters>]

Remove-PSSession [-Id] <Int32[]> [-Confirm] [-WhatIf] [<CommonParameters>]

Remove-PSSession [-InstanceId <Guid[]>] [-Confirm] [-WhatIf] [<CommonParameters>]

Remove-PSSession [-Name <string[]>] [-Confirm] [-WhatIf] [<CommonParameters>]

Remove-PSSession [-Session] <PSSession[]> [-Confirm] [-WhatIf] [<CommonParameters>]

# DESCRIPTION
The Remove-PSSession cmdlet closes Windows PowerShell sessions (PSSessions) in the current session. It stops any commands that are running in the PSSessions, ends the PSSession, and releases the resources that the PSSession was using. If the PSSession is connected to a remote computer, Remove-PSSession also closes the connection between the local and remote computers.

To remove a PSSession, enter the Name, ComputerName, ID, or InstanceID of the session.

If you have saved the PSSession in a variable, the session object remains in the variable, but the state of the PSSession is "Closed."

# PARAMETERS
-ComputerName <string[]>
Closes 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 remote 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[]>
Closes 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
Accept pipeline input? true (ByPropertyName)
Accept wildcard characters? false

-InstanceId <Guid[]>
Closes the PSSessions with the specified instance IDs.

The instance ID is a GUID that uniquely identifies a PSSession in the current session. The InstanceID is unique, even when you have multiple sessions running on a single computer.

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? false

-Name <string[]>
Closes the PSSessions with the specified friendly names. Wildcards are permitted.

Because the friendly name of a PSSession might not be unique, when using the Name parameter, consider also using the WhatIf or Confirm parameter in the Remove-PSSession command.

Required? false
Position? named
Default value
Accept pipeline input? true (ByPropertyName)
Accept wildcard characters? true

-Session <PSSession[]>
Specifies the session objects of the PSSessions to close. Enter a variable that contains the PSSessions or a command that creates or gets the PSSessions, such as a New-PSSession or Get-PSSession command. You can also pipe one or more session objects to Remove-PSSession.

Required? true
Position? 1
Default value
Accept pipeline input? true (ByValue, ByPropertyName)
Accept wildcard characters? false

-Confirm [<SwitchParameter>]
Prompts you for confirmation before executing the command.

Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false

-WhatIf [<SwitchParameter>]
Describes what would happen if you executed the command without actually executing the command.

Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false

<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
System.Management.Automation.Runspaces.PSSession
You can pipe a session object to Remove-PSSession.

# OUTPUTS
None
Remove-PSSession does not return any objects.

# NOTES

The ID parameter is mandatory. You cannot type "remove-pssession" without parameters. To delete all the PSSessions in the current session, type "get-pssession | remove-pssession".

A PSSession uses a persistent connection to a remote computer. Create a PSSession to run a series of commands that share data. For more information, see about_PSSessions.

PSSessions are specific to the current session. When you end a session, the PSSessions that you created in that session are forcibly closed.

# EXAMPLE 1

C:\PS>remove-pssession -id 1, 2

# Description
-----------
This command removes the PSSessions that have IDs 1 and 2.

# EXAMPLE 2

C:\PS>get-pssession | remove-pssession

C:\PS> remove-pssession -session (get-pssession)

C:\PS> $s = get-pssession
C:\PS> remove-pssession -session $s".

# Description
-----------
These commands remove all of the PSSessions in the current session. Although the three command formats look different, they have the same effect.

# EXAMPLE 3

C:\PS>$r = get-pssession -computername Serv*

$r | remove-pssession

# Description
-----------
These commands close the PSSessions that are connected to computers that have names that begin with "Serv".

# EXAMPLE 4

C:\PS>get-pssession | where {$_.port -eq 90} | remove-pssession

# Description
-----------
This command closes the PSSessions that are connected to port 90. You can use this command format to identify PSSessions by properties other than ComputerName, Name, InstanceID, and ID.

# EXAMPLE 5

C:\PS>get-pssession | ft computername, instanceID -auto

ComputerName InstanceId
------------ ----------------
Server01 875d231b-2788-4f36-9f67-2e50d63bb82a
localhost c065ffa0-02c4-406e-84a3-dacb0d677868
Server02 4699cdbc-61d5-4e0d-b916-84f82ebede1f
Server03 4e5a3245-4c63-43e4-88d0-a7798bfc2414
TX-TEST-01 fc4e9dfa-f246-452d-9fa3-1adbdd64ae85

C:\PS> remove-pssession -InstanceID fc4e9dfa-f246-452d-9fa3-1adbdd64ae85

# Description
-----------
These commands show how to close a PSSession based on its instance ID (RemoteRunspaceID).

The first command uses the Get-PSsession cmdlet to get the PSSessions in the current session. It uses a pipeline operator (|) to send the PSSessions to the Format-Table cmdlet (alias: ft), which formats their ComputerName and InstanceID properties in a table. The AutoSize parameter ("auto") compresses the columns for display.

From the resulting display, the administrator can identify the PSSession to be closed, and copy and paste the InstanceID of that PSSession into the second command.

The second command uses the Remove-PSSession cmdlet to remove the PSSession with the specified instance ID.

# EXAMPLE 6

C:\PS>function EndPSS { get-pssession | remove-pssession }

# Description
-----------
This function deletes all of the PSSessions in the current session. After you add this function to your Windows Powershell profile, to delete all sessions, just type "endpss".

RELATED LINKS
Online version: http://go.microsoft.com/fwlink/?LinkID=135250
about_PSSessions
about_Remote
New-PSSession
Get-PSSession
Enter-PSSession
Exit-PSSession
Invoke-Command

C:\Windows>powershell get-help Start-Job -full

ColorConsole [Version 1.7.1000] PowerShell 2.0-Export
Microsoft Windows [Version 6.1.7600]
Copyright (c) 2014 Microsoft Corporation.

OS: Windows-10 / Windows-8.1 & 8 / Windows-7 & Vista / Windows Server 2008-2016
»»»» ColorConsole



 


... Home  
... Impressum
... ColorConsole

... CMD
... Netsh-XP
... Netsh-7
... Netsh-Vista
... Powershell









Download the Windows 7 Starter, Home (Basic Premium), Professional und Ultimate!

... facebook.de
0.077
Wie kann ich das Windows-8 u. 8.1 Kennwort des Benutzerkontos erstellen, ändern, oder entfernen?  / Was ist besser, der FTP-Aktivmodus oder Passivmodus?  / Create Internet Shortcut in the Windows 10 Start Menu?  / Öffnen einer neuen Programminstanz, bzw. Fenster über Windows Start (8.x, 10)!  / In Windows-8.1 alle Benutzer Desktop-Pfad bearbeiten (öffnen, anpassen)!  / Wie kann ich unabsichtlich gelöschte Dateien/Daten wiederherstellen?  / Wie kann ich mehrere Abschnitte vom Text in MS-Word markieren?  / Zu schneller Cursor bei Windows Texteditoren?  / Ein kleines Helferlein habe ich jedoch noch nicht gefunden, so etwas wie "minimize to tray"?  / Soll ich mir eine Update- oder Vollversion von Windows-7 bestellen?  / Wie formatiere ich eine externe Festplatte unter Windows 7?  / Wo kann ich das Passwort meines Benutzers bei Win 7 ändern?  /