[英]How to close every interactive PowerShell session?
Is there a way to exit every interactive PowerShell session created by Enter-PSSession
in PowerShell? 是否可以退出由
Enter-PSSession
在PowerShell中创建的每个交互式PowerShell会话?
I tried something like : 我尝试了类似的东西:
Get-PSSession -ComputerName $computerName -Credential $credential | Exit-PSSession
or 要么
Get-PSSession -ComputerName "pp1KYCiis01" -Credential eperret@vppp.local | foreach { Exit-PSSession $_ }
But does not seem to be right... 但是似乎并不正确...
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.
[...]
Example of Get-PSSession
: 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
and piping Disconnect-PSSession
... 和管道
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
Try Disconnect-PSSession followed by Remove-PSSession : 尝试先断开Disconnect-PSSession,然后再执行Remove-PSSession :
Get-PSSession -ComputerName $computerName -Credential $credential | Disconnect-PSSession | Remove-PSSession
The Remove-PSSession cmdlet closes PowerShell sessions (PSSessions) in the current session.
Remove-PSSession cmdlet将关闭当前会话中的PowerShell会话(PSSessions)。 It stops any commands that are running in the PSSessions, ends the PSSession, and releases the resources that the PSSession was using.
它停止在PSSession中运行的所有命令,结束PSSession,并释放PSSession使用的资源。 If the PSSession is connected to a remote computer, this cmdlet also closes the connection between the local and remote computers.
如果PSSession连接到远程计算机,则此cmdlet还将关闭本地计算机与远程计算机之间的连接。
From get-help Exit-PSSession -full
I can see : 从
get-help Exit-PSSession -full
我可以看到:
Exit-PSSession [] , You cannot pipe objects to this cmdlet.
Exit-PSSession [],无法将对象通过管道传递到此cmdlet。
What I think you are looking for is: 我认为您正在寻找的是:
Get-PSSession | Disconnect-PSSession
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.