0

皆さん、

ボタンクリックでLDAPクエリを処理するように最善を尽くしましたが、dropdown2.textで名前を検索できます。代わりに、「smith、peter」のような完全な名前を付けます。

私が欲しいのは、「マネージャー」フィールドに名または姓のいずれかを入力すると、クリックボタンが表示され、名前または家族名の場合、ActiveDirectoryイベントの対応するすべての値が返されます。遠くはありませんが、どこに間違いがあるのか​​わかりません

function GenerateForm {

set-Location c:\
add-PSSnapin  quest.activeroles.admanagement

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

$form1 = New-Object System.Windows.Forms.Form
$searchldap = New-Object System.Windows.Forms.Button
$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

#Handler 
$handler_searchldap_click= 
{
    $manager = ""
    $dropdown2.items.clear()
    $manager = get-aduser  -f {name -like $dropdown2.text}
    foreach ($thing in $manager){
        $useraccountname = $thing.name
        $DropDown2.Items.Add($useraccountname) | Out-Null
    }
}




$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"
$DropDown2.add_TextUpdate({ Write-Host "TextUpdate. Updated text is: $($Dropdown2.Text)" })
$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
}

###Button section

$searchldap.Location = New-Object System.Drawing.Size(275,80)
$searchldap.Size = New-Object System.Drawing.Size(100,20)
$searchldap.Text = "Search"
$searchldap.Add_Click($handler_searchldap_click)

$Form1.Controls.Add($searchldap)

#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

これを試して:

$filter = [scriptblock]::Create("Name -like '*$($dropdown2.text)*'")
$manager = get-aduser  -f $filter

Powershell は、(AD ゲートウェイ サービス経由で) DC に渡す前に、フィルター スクリプト ブロックで使用されるローカル変数を展開しません。これを回避するには、展開可能な文字列からフィルター スクリプト ブロックを作成します。

于 2013-02-08T15:21:04.917 に答える