Hi All,
Hoping to get some help on this AD Password Reset utility. I'm building a form using .Net objects but when I execute the script it runs the set-adaccountpassword cmdlet before I have a chance to select variable values for password and Username from dropdown. I cant seem to get the execution order of the code correct. Please Help!
CODE:
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
[void] [System.Reflection.Assembly]::LoadWithPartialName('Microsoft.Visualbasic')
$Form = New-Object System.Windows.Forms.Form
$Form.Size = New-Object System.Drawing.Size(600,275)
$form.Name="UCEDC Password Reset"
$form.BackColor="lightGreen"
$form.Text="Company Password Reset Utility"
############################################## Start functions
#$computer=$DropDownBox.SelectedItem.ToString() #populate the var with the value you selected
############################################## end functions
############################################## Start drop down boxes
$DropDownBox = New-Object System.Windows.Forms.ComboBox
$DropDownBox.Location = New-Object System.Drawing.Size(20,50)
$DropDownBox.Size = New-Object System.Drawing.Size(180,20)
$DropDownBox.DropDownHeight = 200
$Form.Controls.Add($DropDownBox)
$wksList=@(get-aduser -filter *| select-object -ExpandProperty samaccountname)
foreach ($wks in $wksList) {
$DropDownBox.Items.Add($wks)
} #end foreach
$passworchange=$DropDownBox.SelectedItem
############################################## end drop down boxes
$Button = New-Object System.Windows.Forms.Button
$Button.Location = New-Object System.Drawing.Size(400,30)
$Button.Size = New-Object System.Drawing.Size(110,80)
$Button.Text = "Reset Password"
$button.add_click({[Microsoft.VisualBasic.interaction]::inputbox("Enter a Password","Password",$passworchange) })
##$Button.Add_Click({procInfo})
$Form.Controls.Add($Button)
Set-ADAccountPassword -Identity $username -NewPassword $passworchange
############################################## Start text fields
$outputBox = New-Object System.Windows.Forms.TextBox
$outputBox.Location = New-Object System.Drawing.Size(10,150)
$outputBox.Size = New-Object System.Drawing.Size(565,200)
$outputBox.MultiLine = $True
$outputBox.ScrollBars = "Vertical"
$outputBox.text= $passworchange
$Form.Controls.Add($outputBox)
############################################## end text fields
############################################## Start buttons
############################################## end buttons
$Form.Add_Shown({$Form.Activate()})
[void] $Form.ShowDialog()