Need help with ssh.net keyboard interactive authentication in PowerShell

Hi,

I am writing a PowerShell script to connect to Linux servers and run few commands. To connect to Linux servers, I am using Renci SSH .NET library. Few Linux flavors do support direct login while some do not. Those Linux servers only support keyboard interactive logins. In case of keyboard interactive authentication, we need to wait for the Linux to prompt for password and we need to detect that in code and pass password.

I have written code for direct login but need some help to write code for keyboard interactive authentication. I think we would need to use eventhandler.

Below is the sample code of login to Linux server with direct authentication (without keyboard interactive authentication)

===================================sample code without keyboard interactive authentication==============================

[void][reflection.assembly]::LoadFrom((Resolve-Path “c:\Deepak\Renci.SshNet.dll”))

$SshClient = New-Object Renci.SshNet.SshClient(“10.31.139.32”, 22, “admin”, “8RttoTriz”)

$SshClient.Connect()

if ($SshClient.IsConnected) {

$SshCommand = $SshClient.RunCommand(“ifconfig”)

$ifconfig = $SshCommand.Result.Split(“`n”)

}

$SshCommand

===================================sample code without keyboard interactive authentication==============================

Below is the error when I try to connect to a Linux server which only supports keyboard interactive authentication

===================================================error==========================================================

PS C:\Deepak> .\testssh.ps1

Exception calling “Connect” with “0” argument(s): "No suitable authentication method found to complete authentication

(publickey,keyboard-interactive)."

At C:\Deepak\testssh.ps1:5 char:1

  • $SshClient.Connect()

  • 
      + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    
      + FullyQualifiedErrorId : SshAuthenticationException
    
    

===================================================error==========================================================

Sample of a keyboard interactive login written in C#

http://stackoverflow.com/questions/15686276/unable-to-connect-to-aixunix-box-with-ssh-net-library-error-value-cannot-b

You can download Renci SSH .Net library from below link

https://sshnet.codeplex.com/downloads/get/944155

Regards,

Deepak

Time to try a Posh-SSH

cant use a module for few reasons,

Please help