簡體   English   中英

在 Powershell 中,當運行“Invoke-SSHCommand”時,它拋出異常,因為找不到“SSHSession”參數

[英]In Powershell when running 'Invoke-SSHCommand' it throws exception as parameter can't be found as 'SSHSession'

我試過如下

$session = New-SSHSession -ComputerName $IPAddress -Credential $creds -AcceptKey
$result = Invoke-SSHCommand -SSHSession $session -Command "hostname"

例外如下

Invoke-SshCommand : A parameter cannot be found that matches parameter name 'SSHSession'.
+ $result = Invoke-SSHCommand -SSHSession $session -Command $updatepack ...
+ CategoryInfo          : InvalidArgument: (:) [Invoke-SshCommand], ParameterBindingException
+ FullyQualifiedErrorId : NamedParameterNotFound,Invoke-SshCommand

我檢查了命令的文檔,如下所示

句法

Invoke-SshCommand [[-ComputerName] <String[]>] [-Command] <String> [-Quiet] [-InvokeOnAll] [<CommonParameters>]

Invoke-SshCommand [[-ComputerName] <String[]>] [-ScriptBlock] <ScriptBlock> [-Quiet] [-InvokeOnAll] [<CommonParameters>]

我看過參數名稱為SSHSession 的示例,不確定我導入的模塊是否版本錯誤。

我假設您已經擁有 Posh-SSH 模塊。 由於您沒有收到錯誤:未被識別為 cmdlet 的名稱

我建議您檢查 POSH-SSH 的版本

Get-module -Name Posh-SSH

或者

Get-command Invoke-SSHCommand 

在此處輸入圖片說明

檢查 Posh-SSH 版本的版本。

如果您使用的是非常舊的版本,請嘗試更新到最新版本。

Install-Module -Name Posh-SSH -RequiredVersion 2.1

“Invoke-SSHCommand”是來自名為“PoshSSH”的 Powershell 模塊的 cmdlet。 如果你想使用它,你需要先安裝它。

請檢查此鏈接以下載/安裝它。

謝謝。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM