3

I'm trying to make a simple PowerShell function to have a Linux-style ssh command. Such as:

ssh username@url

I'm using plink to do this, and this is the function I have written:

function ssh {
    param($usernameAndServer)

    $myArray = $usernameAndServer.Split("@")

    $myArray[0] | C:\plink.exe -ssh $myArray[1]
}

If entered correctly by the user, $myArray[0] is the username and $myArray[1] is the URL. Thus, it connects to the URL and when you're prompted for a username, the username is streamed in using the pipeline. Everything works perfectly, except the pipeline keeps feeding the username ($myArray[0]) and it is entered as the password over and over. Example:

PS C:\Users\Mike> ssh xxxxx@yyyyy
login as: xxxxx@yyyyy's password:
Access denied
xxxxx@yyyyy's password:
Access denied
xxxxx@yyyyy's password:
Access denied
xxxxx@yyyyy's password:
Access denied
xxxxx@yyyy's password:
Access denied
xxxxx@yyyyy's password:
FATAL ERROR: Server sent disconnect message
type 2 (protocol error):
"Too many authentication failures for xxxxx"

Where the username has been substituted with xxxxx and the URL has been substituted with yyyyy.

Basically, I need to find out how to stop the script from piping in the username ($myArray[0]) after it has been entered once.

Any ideas? I've looked all over the internet for a solution and haven't found anything.

1 Answer 1

2

doesn't plink allow you to specify the user and host together in one argument? that is:

plink -ssh user@host

if so your ssh function could be whittled down to:

function ssh {
    param($usernameAndServer)

    C:\plink.exe -ssh $usernameAndServer
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.