我想使用 PowerShell 创建一个 ssh 会话,这就是我使用 Posh-SSh 模块的原因,但是在导入 Posh-SSH 之后,没有加载 New-SSHSession 函数。
代码:
Import-Module -Name Posh-SSH
$targetServer=''
$UserName=''
$PassWord=''
$pass = ConvertTo-SecureString -AsPlainText $PassWord -Force
$cred = New-Object -TypeName System.Managemen.Automation.PSCredential -ArgumentList $UserName,$pass
try
{
$session = New-SSHSession -ComputerName $targetServer -Port "22" -Credential $cred -AcceptKey -Force -Verbose
$result = Invoke-SSHCommand -SSHSession $session -Command "hostname"
Write-Host "OpenFirstSshConnection says: $($result.Output)"
}
catch
{
Write-Error "Exception in first ssh connection (session details: $session): $_"
Write-Host $_.Exception.Message
throw
}
错误:在模块中找到但无法加载的 New-SSHSession。有关更多信息,请运行 Import-Module Posh-SSH。