共用方式為


Exit-PSSession

結束遠端電腦的互動式工作階段。

Syntax

Exit-PSSession []

Description

Cmdlet 會 Exit-PSSession 結束您使用 Cmdlet 啟動的 Enter-PSSession 互動式會話。

您也可以使用 exit 關鍵詞結束互動式會話。 效果與使用 Exit-PSSession相同。

範例

範例 1︰啟動和停止互動式工作階段

PS> Enter-PSSession -ComputerName Server01
Server01\PS> Exit-PSSession
PS>

這些命令會啟動,然後再停止與 Server01 遠端電腦的互動式工作階段。

範例 2︰使用 PSSession 物件啟動和停止互動式工作階段

PS> $s = New-PSSession -ComputerName Server01
PS> Enter-PSSession -Session $s
Server01\PS> Exit-PSSession
PS> $s
Id Name            ComputerName    State    ConfigurationName
-- ----            ------------    -----    -----------------
1  Session1        Server01        Opened   Microsoft.PowerShell

這些命令會使用PowerShell工作階段的Server01電腦啟動和停止互動式會話, (PSSession) 。

由於互動式會話是使用PowerShell工作階段啟動的,因此當互動式會話結束時, 仍可使用 PSSession 。 如果您使用 ComputerName 參數, Enter-PSSession 請建立在互動式工作階段結束時關閉的暫存工作階段。

第一個命令會 New-PSSession 使用 Cmdlet 在 Server01 計算機上建立 PSSession 。 命令會將 PSSession 儲存在 變數中 $s

第二個命令會使用 Enter-PSSession 中的 $sPSSession 來啟動互動式會話。

第三個命令會使用 Exit-PSSession 來停止互動式會話。

最後一個命令會顯示 變數中的 $sPSSessionState 屬性會顯示 PSSession 仍在開啟且可供使用。

範例 3︰使用 Exit 關鍵字停止工作階段

PS> Enter-PSSession -ComputerName Server01
Server01\PS> exit
PS>

此範例會 exit 使用 關鍵詞來停止使用 Enter-PSSession啟動的互動式會話。 關鍵詞 exit 的效果與使用 Exit-PSSession相同。

輸入

None

您無法使用管線將物件傳送至此 Cmdlet。

輸出

None

此 Cmdlet 不會傳回任何輸出。

備註

PowerShell 包含的下列別名 Exit-PSSession

  • 所有平台:
    • exsn

此 Cmdlet 只採用一般的參數。