Exit-PSSession
結束與遠端電腦的互動工作階段。
語法
Default (預設值)
Exit-PSSession
Description
Exit-PSSession指令長會結束你用指令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)的 Server01 電腦互動式會話。
由於互動式會話是以 PowerShell 會話啟動,當互動式會話結束時, PSSession 仍然可用。 如果你使用 ComputerName 參數,會 Enter-PSSession 建立一個臨時工作階段,當互動式工作階段結束時關閉。
第一個指令使用 New-PSSession cmdlet 在 Server01 電腦上建立 PSSession 。 指令會將 PSSession 儲存在變數中 $s 。
第二個指令用於 Enter-PSSession 啟動互動式工作階段,使用 PSSession 中的 $s。
第三個指令用於 Exit-PSSession 停止互動會話。
最後一個指令會在變數中顯示 PSSession$s。
州政府財產顯示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
此指令小程式僅取常見參數。