Pipelining String in Powershell

Posted by ChvyVele on Stack Overflow See other posts from Stack Overflow or by ChvyVele
Published on 2011-01-12T03:48:16Z Indexed on 2011/01/12 3:53 UTC
Read the original article Hit count: 170

Filed under:
|
|
|
|

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.

© Stack Overflow or respective owner

Related posts about Windows

Related posts about scripting