plink请求变量powershell

时间:2018-06-05 12:49:16

标签: powershell variables unix plink

我有以下代码:

& $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

没有任何作用:(

如何将命令输出变为变量?

1 个答案:

答案 0 :(得分:1)

$example = Invoke-Expression "$Plinkpath -P '22' -v 'User@Server' -pw $passw $commands" 是否适合您?

$example

这应该将命令输出捕获到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. 变量。

以下是cmdlet说明:

map