AustenKing

Powershell GUI Template

Jan 26th, 2021
981
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #Generates the Window
  2. $Form = New-Object System.Windows.Forms.Form    
  3. $Form.text ="Disable Prompt"
  4.  
  5. #Gets a list of users
  6. $users = Get-LocalUser | Where-Object -Match Enabled True
  7.  
  8. #Makes each checkbox
  9. $y = 20
  10. foreach ($user in $users)
  11. {    
  12.     $Checkbox = New-Object System.Windows.Forms.CheckBox
  13.     $Checkbox.Text = $user.Name
  14.     $Checkbox.Location = New-Object System.Drawing.Size(10,$y)
  15.     $y += 40
  16.     $Form.Controls.Add($Checkbox)
  17. }
  18.  
  19. #Sets the window size based on how many checkboxes
  20. $Form.size = New-Object System.Drawing.Size(300,($y + 120))
  21.  
  22.  
  23. # Add Button
  24. $Button = New-Object System.Windows.Forms.Button
  25. $Button.Location = New-Object System.Drawing.Size(100,($y + 20))
  26. $Button.Text = "Lock"
  27.  
  28. #Add Button event
  29. $Button.Add_Click(
  30.     {    
  31.             $Checkboxes | Where-Object -Match Checked True | ForEach-Object { $_.Text } | Disable-LocalUser -WhatIf
  32.             $Form.close()
  33.     }
  34. )
  35.  
  36. #Add button to window
  37. $Form.Controls.Add($Button)
  38.    
  39. #Display window
  40. $Form.ShowDialog()
RAW Paste Data