[英]Execution of interactive command in remote Powershell session not working
[英]How to close every interactive PowerShell session?
是否可以退出由Enter-PSSession
在PowerShell中創建的每個交互式PowerShell會話?
我嘗試了類似的東西:
Get-PSSession -ComputerName $computerName -Credential $credential | Exit-PSSession
要么
Get-PSSession -ComputerName "pp1KYCiis01" -Credential eperret@vppp.local | foreach { Exit-PSSession $_ }
但是似乎並不正確...
Exit-PSSession : The input object cannot be bound to any parameters for the command either because the command does not take
pipeline input or the input and its properties do not match any of the parameters that take pipeline input.
[...]
Get-PSSession
示例:
PS C:\Users\eperret> Get-PSSession -ComputerName $computerName -Credential $credential
Id Name ComputerName ComputerType State ConfigurationName Availability
-- ---- ------------ ------------ ----- ----------------- ------------
36 WinRM7 computerNam RemoteMachine Disconnected Microsoft.PowerShell Busy
37 WinRM4 computerNam RemoteMachine Disconnected Microsoft.PowerShell Busy
38 WinRM2 computerNam RemoteMachine Disconnected Microsoft.PowerShell Busy
39 WinRM5 computerNam RemoteMachine Disconnected Microsoft.PowerShell Busy
40 WinRM3 computerNam RemoteMachine Disconnected Microsoft.PowerShell Busy
和管道Disconnect-PSSession
...
PS C:\Users\eperret> Get-PSSession -ComputerName $computerName -Credential $credential | Disconnect-PSSession
Id Name ComputerName ComputerType State ConfigurationName Availability
-- ---- ------------ ------------ ----- ----------------- ------------
46 WinRM7 computerNam RemoteMachine Disconnected Microsoft.PowerShell Busy
47 WinRM4 computerNam RemoteMachine Disconnected Microsoft.PowerShell Busy
48 WinRM2 computerNam RemoteMachine Disconnected Microsoft.PowerShell Busy
49 WinRM5 computerNam RemoteMachine Disconnected Microsoft.PowerShell Busy
50 WinRM3 computerNam RemoteMachine Disconnected Microsoft.PowerShell Busy
嘗試先斷開Disconnect-PSSession,然后再執行Remove-PSSession :
Get-PSSession -ComputerName $computerName -Credential $credential | Disconnect-PSSession | Remove-PSSession
Remove-PSSession cmdlet將關閉當前會話中的PowerShell會話(PSSessions)。 它停止在PSSession中運行的所有命令,結束PSSession,並釋放PSSession使用的資源。 如果PSSession連接到遠程計算機,則此cmdlet還將關閉本地計算機與遠程計算機之間的連接。
從get-help Exit-PSSession -full
我可以看到:
Exit-PSSession [],無法將對象通過管道傳遞到此cmdlet。
我認為您正在尋找的是:
Get-PSSession | Disconnect-PSSession
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.