KBNanda
KBNanda

Reputation: 665

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.

Upvotes: 0

Views: 5711

Answers (2)

Satya V
Satya V

Reputation: 4174

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 

enter image description here

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

Upvotes: 1

Klausen
Klausen

Reputation: 101

"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.

Upvotes: 0

Related Questions