首页 > 解决方案 > Start-Process powershell 未将结果添加到文本框

问题描述

我正在尝试将命令输出添加到文本框。但它什么也没做。我错过了什么?我直接在 Powershell 控制台中尝试了该命令,它工作正常,我可以在那里看到输出。但是为什么它没有在文本框中显示输出呢?

这是我的代码

$showstatussh = {plink admin@192.168.1.1 -pw '' -m E:\PSGTM\statussh.txt}

$button_click = {
$textboxResults.Text = Start-Process powershell -ArgumentList "-Command $showstatussh"
}

$Form = New-Object System.Windows.Forms.Form
$Form.Text = "my control"
$Form.Size = New-Object System.Drawing.Size(300,300)
$Form.StartPosition = "CenterScreen"
$Form.Topmost = $True

$StatusS = New-Object System.Windows.Forms.Button
$StatusS.Location = New-Object System.Drawing.Size(30,150)
$StatusS.Size = New-Object System.Drawing.Size(230,30)
$StatusS.Text = "Show Status"
$StatusS.BackColor = [System.Drawing.ColorTranslator]::FromHtml("#cdafa8")
$StatusS.Add_Click($button_click)

$textboxResults = New-Object System.Windows.Forms.TextBox
$textboxResults.Location = New-Object System.Drawing.Point(10,190)
$textboxResults.Size = New-Object System.Drawing.Size(100,20)

$Form.Controls.AddRange(($StatusS, $textboxResults))

$form.showdialog()

标签: formspowershellbuttontextbox

解决方案


我想我想出了解决方案

代替:

$button_click = {
$textboxResults.Text = Start-Process powershell -ArgumentList "-Command $showstatussh"
}

我做了:

$button_click = {
$textboxResults.Text = .$showstatussh
}

推荐阅读