Powershell conveyor line

I am trying to make a simple PowerShell function for a Linux-style ssh command. For instance:

ssh username@url

I use plink for this and this is the function I wrote:

function ssh {
    param($usernameAndServer)

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

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

When entered correctly by the user, $ myArray [0] is the name of the user, and $ myArray [1] is the URL. Thus, it connects to the URL, and when you are prompted for a username, the username will be broadcast using the pipeline. Everything works fine, except that the pipeline continues to feed the username ($ myArray [0]), and it is entered as a password again and again. Example:

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

If the username has been replaced by xxxxx and the URL has been replaced by yyyyy.

, , script ($ myArray [0]) , .

? .

+3
1

, ? :

plink -ssh user @host

ssh :

function ssh {
    param($usernameAndServer)

    C:\plink.exe -ssh $usernameAndServer
}
+2

Source: https://habr.com/ru/post/1784882/


All Articles