plink 和 PowerShell 的参数问题
Parameter issue with plink and PowerShell
我正在尝试使用 plink 通过 ssh 连接到交换机,但我的参数总是出错。
$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
据我所知,我的参数是正确的,知道为什么它不起作用吗?
你需要告诉 powershell 你是 运行 一个带参数的命令,否则它不知道如何解释你的参数列表,要让它工作,你可以简单地添加 &
命令前的符号:
& $plink -l $username -pw $pw -m $commands -ssh $switch
我正在尝试使用 plink 通过 ssh 连接到交换机,但我的参数总是出错。
$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
据我所知,我的参数是正确的,知道为什么它不起作用吗?
你需要告诉 powershell 你是 运行 一个带参数的命令,否则它不知道如何解释你的参数列表,要让它工作,你可以简单地添加 &
命令前的符号:
& $plink -l $username -pw $pw -m $commands -ssh $switch