Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Load the assemblies needed for drawing forms with PowerShell
- [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
- [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
- #region to draw the background form
- $Form = New-Object System.Windows.Forms.Form
- $Form.Text = "Unlock Unlock Tool"
- $Form.Size = New-Object System.Drawing.Size(300,140)
- $Form.StartPosition = "CenterScreen"
- $Form.KeyPreview = $True
- $Form.MaximumSize = $Form.Size
- $Form.MinimumSize = $Form.Size
- #begin to draw text box
- $textbox = New-Object System.Windows.Forms.TextBox
- $textbox.Location = New-Object System.Drawing.Size(10,40)
- $textbox.Size = New-Object System.Drawing.Size(200,20)
- $textbox.Height = 80
- $textbox.Name = 'TextBox_UserName'
- $textbox.AutoCompleteSource = 'CustomSource'
- $textbox.AutoCompleteMode='SuggestAppend'
- $textbox.AutoCompleteCustomSource=$autocomplete
- #Auto Complete Fields
- Get-ADUser -Filter {enabled -eq $True}| Select -expandproperty Samaccountname | % {$textbox.AutoCompleteCustomSource.AddRange($_) }
- $Form.Controls.Add($textbox)
- #begin to draw an OK button
- $OKButton = New-Object System.Windows.Forms.Button
- $OKButton.Location = New-Object System.Drawing.Size(220,38)
- $OKButton.Size = New-Object System.Drawing.Size(60,40)
- $OKButton.Text = "Unlock"
- $OKButton.Add_Click({$xdept=$ListBox.SelectedItem;$xname=$TextBox.Text;$xfname=$TextBoxfName.Text;$Form.Close()
- })
- $Form.Controls.Add($OKButton)
- #Make our form topmost, then show it
- $Form.Topmost = $True
- $Form.Add_Shown({$Form.Activate()})
- [void] $Form.ShowDialog()
- #Return the value
- #creating object os WScript
- $OKButton.Add_Click({
- $name = get-aduser -Identity $textbox.Text | select -ExpandProperty Name
- Unlock-ADAccount $textbox.Text
- $wshell = New-Object -ComObject Wscript.Shell
- $Output = $wshell.Popup("$name is now unlocked!")
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement