Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #Load the assemblies needed for drawing forms with PowerShell
  2. [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
  3. [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
  4.  
  5. #region to draw the background form
  6. $Form = New-Object System.Windows.Forms.Form
  7. $Form.Text = "Unlock Unlock Tool"
  8. $Form.Size = New-Object System.Drawing.Size(300,140)
  9. $Form.StartPosition = "CenterScreen"
  10. $Form.KeyPreview = $True
  11. $Form.MaximumSize = $Form.Size
  12. $Form.MinimumSize = $Form.Size
  13.  
  14. #begin to draw text box
  15. $textbox = New-Object System.Windows.Forms.TextBox
  16. $textbox.Location = New-Object System.Drawing.Size(10,40)
  17. $textbox.Size = New-Object System.Drawing.Size(200,20)
  18. $textbox.Height = 80
  19. $textbox.Name = 'TextBox_UserName'
  20. $textbox.AutoCompleteSource = 'CustomSource'
  21. $textbox.AutoCompleteMode='SuggestAppend'
  22. $textbox.AutoCompleteCustomSource=$autocomplete
  23.  
  24. #Auto Complete Fields
  25. Get-ADUser -Filter {enabled -eq $True}| Select -expandproperty Samaccountname  | % {$textbox.AutoCompleteCustomSource.AddRange($_) }
  26. $Form.Controls.Add($textbox)
  27.  
  28. #begin to draw an OK button
  29. $OKButton = New-Object System.Windows.Forms.Button
  30. $OKButton.Location = New-Object System.Drawing.Size(220,38)
  31. $OKButton.Size = New-Object System.Drawing.Size(60,40)
  32. $OKButton.Text = "Unlock"
  33. $OKButton.Add_Click({$xdept=$ListBox.SelectedItem;$xname=$TextBox.Text;$xfname=$TextBoxfName.Text;$Form.Close()
  34.  
  35.  
  36. })
  37. $Form.Controls.Add($OKButton)
  38.  
  39. #Make our form topmost, then show it
  40. $Form.Topmost = $True
  41. $Form.Add_Shown({$Form.Activate()})
  42. [void] $Form.ShowDialog()
  43.  
  44. #Return the value
  45.  
  46. #creating object os WScript
  47.  
  48. $OKButton.Add_Click({
  49. $name = get-aduser -Identity $textbox.Text | select -ExpandProperty Name
  50. Unlock-ADAccount $textbox.Text
  51. $wshell = New-Object -ComObject Wscript.Shell
  52. $Output = $wshell.Popup("$name is now unlocked!")
  53. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement