简体   繁体   中英

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

I tried as below

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

The exception is as below

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

I checked the documentation for the command and it was as below

SYNTAX

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

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

I have seen examples with parameter name as SSHSession , not sure whether the module i imported is wrong version or not.

I assume that you already have the Posh-SSH module. ( Since you are not getting the Error : is not recognized as the name of a cmdlet )

I would advice you to check the version of the POSH-SSH

Get-module -Name Posh-SSH

Or

Get-command Invoke-SSHCommand 

在此处输入图片说明

Check the version of the Posh-SSH Version.

Try updating to the latest one if you are in a very old version.

Install-Module -Name Posh-SSH -RequiredVersion 2.1

"Invoke-SSHCommand" is a cmdlet from the Powershell module called "PoshSSH". If you want to use it, you need to install it first.

Please check this link for downloading / installing it.

Thanks.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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