Есть ли способ выйти из каждого интерактивного сеанса PowerShell, созданного Enter-PSSession
в 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