Outputting to a GUI Powershell



希望你能帮上忙。

我有下面的代码,我正在运行以获得AD用户所在组的列表。

我已经创建了如下所示的GUI,我试图让AD命令的输出出现在GUI中,在那里我创建了一个文本框。

我的两个问题是:

  1. 如果你点击'Search', GUI窗口关闭。
  2. 如果你删除行来保持GUI窗口关闭,它不会输出任何内容到文本框。

任何帮助将不胜感激-真的认为这是我错过的一行代码!由于

$testform.StartPosition = 'CenterScreen'
$okb = New-Object System.Windows.Forms.Button
$okb.Location = New-Object System.Drawing.Point(85,130)
$okb.Size = New-Object System.Drawing.Size(75,25)
$okb.Text = 'Search'
$okb.DialogResult = [System.Windows.Forms.DialogResult]::OK
$testform.AcceptButton = $okb
$testform.Controls.Add($okb)
$test.Location = New-Object System.Drawing.Point(270,130)
$test.Size = New-Object System.Drawing.Size(75,25)
$test.Text = 'close'
$test.DialogResult = [System.Windows.Forms.DialogResult]::Cancel
$testform.AcceptButton = $test
$testform.Controls.Add($test)
$lb = New-Object System.Windows.Forms.Label
$lb.Location = New-Object System.Drawing.Point(20,40)
$lb.Size = New-Object System.Drawing.Size(240,20)
$lb.Text = 'Please enter the username:'
$testform.Controls.Add($lb)
$tb = New-Object System.Windows.Forms.TextBox
$tb.Location = New-Object System.Drawing.Point(40,80)
$tb.Size = New-Object System.Drawing.Size(240,20)
$textBoxDisplay = New-Object 'System.Windows.Forms.TextBox'
$textBoxDisplay.Location = '30, 175'
$textBoxDisplay.Multiline = $true
$textBoxDisplay.Name = "textBoxDisplay"
$textBoxDisplay.Size = '470, 150'
$textBoxDisplay.TabIndex = 1
$testform.Controls.Add($tb)
$testform.Controls.Add($textBoxDisplay)
$testform.Topmost = $true
$testform.Add_Shown({$tb.Select()})
$rs = $testform.ShowDialog()
if ($rs -eq [System.Windows.Forms.DialogResult]::OK)
{
$y = $tb.Text
$answer = (Get-ADUser $y  -Properties MemberOf).memberof | Get-ADGroup | Select-Object name ```

您可以将您的函数定义为:

$Button_Click = {
$y = $tb.Text
$answer = ....
$textBoxDisplay.Text=$answer
}

并使用Add_Click(...):

将其分配给按钮单击事件
$okb.Add_Click($Button_Click)

,然后显示对话框:

$testform.ShowDialog()

相关内容

  • 没有找到相关文章

最新更新