plink 请求变量 powershell
plink request to variable powershell
我有以下代码:
& $Plinkpath -P "22" -v "User@Server" -pw $passw $commands3 | Out-File $Report -Append -Encoding utf8
这会输出一个包含所需信息的文件,但我想将 plink 语句结果存储到一个变量中。
我试过了:
& $Plinkpath -P "22" -v "User@Server" -pw $passw $commands > $Example
$Example = $Plinkpath -P "22" -v "User@Server" -pw $passw $commands
没有任何效果:(
如何将命令输出放入变量中?
Invoke-Expression
对你有用吗?
$example = Invoke-Expression "$Plinkpath -P '22' -v 'User@Server' -pw $passw $commands"
这应该将命令输出捕获到 $example
变量中。
以下是 cmdlet 描述:
PS > Get-Help invoke-expression
NAME
Invoke-Expression
SYNOPSIS
Runs commands or expressions on the local computer.
SYNTAX
Invoke-Expression [-Command] <String> [<CommonParameters>]
DESCRIPTION
The Invoke-Expression cmdlet evaluates or runs a specified string as a command and returns the results of the
expression or command. Without Invoke-Expression , a string submitted at the command line would be returned
(echoed) unchanged.
我有以下代码:
& $Plinkpath -P "22" -v "User@Server" -pw $passw $commands3 | Out-File $Report -Append -Encoding utf8
这会输出一个包含所需信息的文件,但我想将 plink 语句结果存储到一个变量中。
我试过了:
& $Plinkpath -P "22" -v "User@Server" -pw $passw $commands > $Example
$Example = $Plinkpath -P "22" -v "User@Server" -pw $passw $commands
没有任何效果:(
如何将命令输出放入变量中?
Invoke-Expression
对你有用吗?
$example = Invoke-Expression "$Plinkpath -P '22' -v 'User@Server' -pw $passw $commands"
这应该将命令输出捕获到 $example
变量中。
以下是 cmdlet 描述:
PS > Get-Help invoke-expression
NAME
Invoke-Expression
SYNOPSIS
Runs commands or expressions on the local computer.
SYNTAX
Invoke-Expression [-Command] <String> [<CommonParameters>]
DESCRIPTION
The Invoke-Expression cmdlet evaluates or runs a specified string as a command and returns the results of the
expression or command. Without Invoke-Expression , a string submitted at the command line would be returned
(echoed) unchanged.