共用方式為


Exit-PSSession

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

Syntax

Exit-PSSession []

Description

Exit-PSSession Cmdlet 結束您使用 Enter-PSSession Cmdlet 啟動的互動式工作階段。

您也可以使用 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

這些命令會啟動和停止與 Server01 計算機搭配使用 PowerShell 工作階段的互動式會話, (PSSession) 。

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

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

第二個命令使用 Enter-PSSession 使用 $s 中的 PSSession 啟動互動式工作階段。

第三個命令使用 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 不會傳回任何輸出。

備註

  • 此 Cmdlet 只採用一般的參數。