1

对于像你这样有经验的人来说,这可能是一个简单的问题,但是我怎样才能在下拉菜单中对用户名进行实时 Active Directory 搜索,获取所选结果并将值传递给$var

这是我的 from 和我的两个下拉菜单,我希望下拉菜单manager根据我输入的字符串在我的 Active Directory 中进行查找。即,如果我输入Macdonald下拉项目,将在我的 AD 中显示所有 Macdonald 的名字或姓氏。

function GenerateForm {

[reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null
[reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null

$form1 = New-Object System.Windows.Forms.Form
$DropDownLabel = new-object System.Windows.Forms.Label
$DropDownLabel2 = new-object System.Windows.Forms.Label
$DropDown = new-object System.Windows.Forms.ComboBox
$DropDown2 = new-object System.Windows.Forms.ComboBox


$InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState

$OnLoadForm_StateCorrection=
{#Correct the initial state of the form to prevent the .Net maximized form issue
    $form1.WindowState = $InitialFormWindowState
}

#----------------------------------------------
#region Generated Form Code
$form1.Text = "User Creation software"
$form1.Name = "form1"
$form1.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 400
$System_Drawing_Size.Height = 200
$form1.ClientSize = $System_Drawing_Size

$DropDownArray = "Site1" , "Site2" , "Site3"

$DropDown2.Location = new-object System.Drawing.Size(125,80)
$DropDown2.Size = new-object System.Drawing.Size(150,27)
$dropdown2.DataBindings.DefaultDataSourceUpdateMode = 0
$dropdown2.TabIndex = 5
$dropdown2.Name = "dropdown2"
$Form1.Controls.Add($DropDown2)

$DropDownLabel2 = new-object System.Windows.Forms.Label
$DropDownLabel2.Location = new-object System.Drawing.Size(50,80)
$DropDownLabel2.size = new-object System.Drawing.Size(50,27)
$DropDownLabel2.Text = "Manager:"
$Form1.Controls.Add($DropDownLabel2)

$DropDown.Location = new-object System.Drawing.Size(125,55)
$DropDown.Size = new-object System.Drawing.Size(150,27)
$dropdown.DataBindings.DefaultDataSourceUpdateMode = 0
$dropdown.TabIndex = 4
$dropdown.Name = "dropdown1"

$DropDownLabel = new-object System.Windows.Forms.Label
$DropDownLabel.Location = new-object System.Drawing.Size(50,58)
$DropDownLabel.size = new-object System.Drawing.Size(50,27)
$DropDownLabel.Text = "Location:"

$Form1.Controls.Add($DropDown)
$Form1.Controls.Add($DropDownLabel)

ForEach ($Item in $DropDownArray) {
$DropDown.Items.Add($Item) | Out-Null
}

#Save the initial state of the form
$InitialFormWindowState = $form1.WindowState
#Init the OnLoad event to correct the initial state of the form
$form1.add_Load($OnLoadForm_StateCorrection)
#Show the Form
$form1.ShowDialog()| Out-Null
} #end of function
GenerateForm
4

1 回答 1

2

要进行实时更新,您需要在修改 Dropbox 中的文本时更新列表。当您在其中写入时,至少会触发 2 个事件:TextUpdateKeyPress. 选一个。我建议TextUpdate,因为它在文本更改后KeyPress做出反应,而在之前做出反应。您可以使用例如添加事件监听器:

$DropDown2.add_TextUpdate({ Write-Host "TextUpdate. Updated text is: $($Dropdown2.Text)" })

在脚本块中,您需要运行一个查询 DC 的函数,但这个问题没有用 ADSI、AD、LDAP 等标记,所以这是另一个问题。

请注意,每次更改导致 DC 额外负载的字母时,都会运行查询。例如,如果你想写“Mark”,它会在你写完之前搜索至少 4 次。

我建议使用带有搜索按钮的文本框来尽量减少不必要的流量。

于 2013-02-06T22:55:04.477 回答