带Powershell问题的ConvertTo-HTML

时间:2011-03-07 01:22:01

标签: powershell

我正在尝试使用PowerShell将文本框中输入的值输出到HTML,但我有点卡住了。这是我的代码:

$button1 = New-Object System.Windows.Forms.Button
$button1.Name = "button1"
$button1.Location = New-Object System.Drawing.Point(16, 350)
$button1.Text = "Create"
$button1.add_Click({ConvertTo-HTML -title "Email Signature" -body "<p>$textBox2.Text</p>"})

生成的HTML是......

System.Windows.Forms.TextBox, Text: Chris.Text

如何将输出简单地设为“Chris”?

2 个答案:

答案 0 :(得分:0)

完成了工作:)

答案是:$($ textBox2.Text)

答案 1 :(得分:0)

您可以将变量包装在()或{}中,以便在括在“”。

中时检索该值

例如,

$button1.add_Click({ConvertTo-HTML -title "Email Signature" -body "<p>$($textBox2.Text)</p>"})

$button1.add_Click({ConvertTo-HTML -title "Email Signature" -body "<p>${textBox2.Text}</p>"})