Exit-PSSession
結束遠端電腦的互動式會話。
語法
Default (預設值)
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
這些命令會使用PowerShell工作階段的Server01電腦啟動和停止互動式工作階段(PSSession)。
由於互動式會話是使用 PowerShell 工作階段啟動的,因此當互動式會話結束時,PSSession 仍然可用。 如果您使用 ComputerName 參數,Enter-PSSession 會建立一個臨時會話,並在互動式會話結束時將其關閉。
第一個命令會使用 New-PSSession Cmdlet,在 Server01 計算機上建立 PSSession。 此命令會將 PSSession 儲存在 $s 變數中。
第二個命令會使用 Enter-PSSession,在 中使用 $s 啟動互動式會話。
第三個命令會使用 Exit-PSSession 來停止互動式會話。
最後一個命令會顯示 變數中的 $s。
State 屬性會顯示 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 只會接受一般參數。