Powershell 测试是否连接了ssh会话失败

Powershell 测试是否连接了ssh会话失败,powershell,Powershell,我在Windows Server 2008 R2中的PowerShell脚本中使用了ssh会话module 1.4版本,但在Windows Server 2019中安装sshsessionmodule 2.1.3后,出现了一些问题 我尝试了if-not 我用一个变量尝试了-eq if (! (Get-SshSession -ComputerName $MAST_NAME).connected) { New-SshSession -ComputerName $MAST_NAME -User

我在Windows Server 2008 R2中的PowerShell脚本中使用了
ssh会话
module 1.4版本,但在Windows Server 2019中安装
sshsession
module 2.1.3后,出现了一些问题

我尝试了
if-not

我用一个变量尝试了
-eq

if (! (Get-SshSession -ComputerName $MAST_NAME).connected) {
    New-SshSession -ComputerName $MAST_NAME -Username $USR_REMOTE_MAST_NAME -Password $USR_REMOTE_MAST_PASSWD
}
使用1.4
ssh会话
模块,测试
if(!(get……)
工作正常。
使用2.1.3
sshsession
模块(注意名称已更改),下面的代码不起作用。

创建新的sshsession时,会创建一个$SshSessions变量。请尝试使用它首先查找所需的主机,然后检查其状态。例如:

ForEach ($SshSession in $SshSessions){
If (($SshSession.Host -eq $MAST_NAME) -and ($SshSession.Connected -eq "true")){
  Write-Host '$MAST_NAME is connected'
}
Else {
  New-SshSession -ComputerName $MAST_NAME -Creditials...}}