输出到Gui Powershell

发布于 2025-02-13 07:36:00 字数 1755 浏览 0 评论 0原文

希望您能提供帮助。

我有以下我正在运行的代码以获取广告用户所在的组列表。

我创建了GUI,如下创建了一个文本框。

我的两个问题是:

  1. 如果您单击“搜索”,则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 ```

Hope you can help.

I have the below code that I am running to get a list of the groups an AD user is in.

I have created the GUI as below and I am trying to get the output of the AD command to appear inside the GUI, where I have created a text box.

My two issues are:

  1. If you click 'Search', the GUI window closes.
  2. If you remove lines to keep the GUI window from closing, it doesn't output anything to the text box.

Any help would be appreciated - really think it is a line of code I am missing! Thanks

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

許願樹丅啲祈禱 2025-02-20 07:36:01

您可以将函数定义为:

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

并使用add_click(...)

$okb.Add_Click($Button_Click)

然后显示对话框:

$testform.ShowDialog()

You may define your function as:

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

and assign it to the button click event using Add_Click(...):

$okb.Add_Click($Button_Click)

and then show the dialog:

$testform.ShowDialog()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文