繁体   English   中英

如何关闭每个交互式PowerShell会话?

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM