Powershell 中的管道化字符串
我正在尝试创建一个简单的 PowerShell 函数来执行 Linux 风格的 ssh 命令。如:
ssh username@url
我使用plink来做到这一点,这是我编写的函数:
function ssh {
param($usernameAndServer)
$myArray = $usernameAndServer.Split("@")
$myArray[0] | C:\plink.exe -ssh $myArray[1]
}
如果用户输入正确,$myArray[0]是用户名,$myArray [1] 是网址。因此,它连接到 URL,当提示您输入用户名时,用户名将使用管道流式传输。一切都运行良好,除了管道不断输入用户名($myArray[0])并且一遍又一遍地输入它作为密码。示例:
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"
用户名已替换为 xxxxx,URL 已替换为 yyyyy。
基本上,我需要找出如何在用户名 ($myArray[0]) 输入一次后停止脚本的管道传输。
有什么想法吗?我在互联网上寻找解决方案,但没有找到任何东西。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
plink 不允许您在一个参数中同时指定用户和主机吗?即:
plink -ssh user@host
如果是的话,您的 ssh 功能可以缩减为:
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: