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工作階段 (PSSession) 的Session( Server01 電腦啟動和停止互動式會話」。

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

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

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

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

最後一個命令會顯示 變數中的 $s PSSessionState 屬性會顯示 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 只會接受一般參數。