plink和PowerShell的参数问题

时间:2015-09-15 08:50:36

标签: powershell ssh plink

我正在尝试使用plink进入交换机,但我的参数一直出错。

$plink = 'C:\Program Files (x86)\PuTTY\plink.exe'
$switch = "172.20.19.50"
$commands = "c:\scripts\cmd.txt"
$username = Read-Host "User name"
$pw =  Read-Host -Prompt "Enter password" -AsSecureString
$plink -l $username -pw $pw -m $commands -ssh $switch 

这些是我得到的错误:

You must provide a value expression on the right-hand side of the '-' operator.
At line:7 char:8

Unexpected token 'l' in expression or statement.
At line:7 char:9

Unexpected token 'username' in expression or statement.
At line:7 char:11

Unexpected token '-pw' in expression or statement.
At line:7 char:21

Unexpected token 'pw' in expression or statement.
At line:7 char:25

Unexpected token '-m' in expression or statement.
At line:7 char:29

Unexpected token 'commands' in expression or statement.
At line:7 char:32

Unexpected token '-ssh' in expression or statement.
At line:7 char:42

Unexpected token 'switch' in expression or statement.
At line:7 char:47

就我所见,我的参数是正确的,知道它为什么不起作用?

1 个答案:

答案 0 :(得分:1)

您需要告诉powershell您正在运行带参数的命令,否则它不知道如何解释您的参数列表,为了使其正常工作,您只需在您的符号之前添加&符号命令:

& $plink -l $username -pw $pw -m $commands -ssh $switch