daily pastebin goal
76%
SHARE
TWEET

Form Script

a guest May 16th, 2018 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. Import-Module ActiveDirectory
  3.  
  4.  
  5. Add-Type -AssemblyName System.Drawing
  6. Add-Type -AssemblyName System.Windows.Forms
  7.  
  8.  
  9.  
  10. #--------------------------------------------------------------------------------------
  11. #Form 1 Start
  12.  
  13.  
  14.        
  15.         #ListBox - Non-Exempt
  16.        
  17.         $listboxNonExempt = New-Object System.Windows.Forms.ListBox
  18.         $listboxNonExempt.FormattingEnabled = $True
  19.         $listboxNonExempt.Location = New-Object System.Drawing.Point(6, 27)
  20.         $listboxNonExempt.Size = New-Object System.Drawing.Size(188, 108)
  21.        
  22.        
  23.         #Form - Panel
  24.        
  25.         $formPanel = New-Object System.Windows.Forms.Panel
  26.         $formPanel.Location = New-Object System.Drawing.Point(12, 14)
  27.         $formPanel.Size = New-Object System.Drawing.Size(442, 327)
  28.        
  29.        
  30.  
  31.        
  32.  
  33.         #GroupBox - Non-Exempt
  34.        
  35.         $groupboxNonExempt = New-Object System.Windows.Forms.GroupBox
  36.         $groupboxNonExempt.Location = New-Object System.Drawing.Point(223, 74)
  37.         $groupboxNonExempt.Size = New-Object System.Drawing.Size(200, 164)
  38.         $groupboxNonExempt.Text = "Non-Exempt"
  39.        
  40.        
  41.         #GroupBox - Name and All
  42.        
  43.         $groupboxName = New-Object System.Windows.Forms.GroupBox
  44.         $groupboxName.Location = New-Object System.Drawing.Point(3, 3)
  45.         $groupboxName.Size = New-Object System.Drawing.Size(436, 320)
  46.         $groupboxName.Text = "Name"
  47.  
  48.        
  49.         #ComboBox - Name Search
  50.        
  51.         $comboboxNameSearch = New-Object System.Windows.Forms.TextBox
  52.        
  53.         $comboboxNameSearch.Location = New-Object System.Drawing.Point(6, 19)
  54.         $comboboxNameSearch.Size = New-Object System.Drawing.Size(223, 21)
  55.  
  56.        
  57.         #Button - Find
  58.        
  59.         $bnFind = New-Object System.Windows.Forms.Button
  60.         $bnFind.Location = New-Object System.Drawing.Point(235, 19)
  61.         $bnFind.Size = New-Object System.Drawing.Size(35, 23)
  62.         $bnFind.Text = "Add"
  63.         $bnFind.UseVisualStyleBackColor = $True
  64.        
  65.        
  66.  
  67.    
  68.  
  69.        
  70.  
  71.  
  72.  
  73.        
  74.  
  75.  
  76.        
  77.         #Button OK Form
  78.  
  79.         $bnOKForm = New-Object System.Windows.Forms.Button
  80.         $bnOKForm.Location = New-Object System.Drawing.Point(223, 274)
  81.         $bnOKForm.Size = New-Object System.Drawing.Size(75, 23)
  82.         $bnOKForm.Text = "OK"
  83.         $bnOKForm.UseVisualStyleBackColor = $True
  84.        
  85.         #Button Cancel Form
  86.        
  87.         $bnCancelForm = New-Object System.Windows.Forms.Button
  88.         $bnCancelForm.Location = New-Object System.Drawing.Point(131, 274)
  89.         $bnCancelForm.Size = New-Object System.Drawing.Size(75, 23)
  90.         $bnCancelForm.Text = "Cancel"
  91.         $bnCancelForm.UseVisualStyleBackColor = $True
  92.        
  93.  
  94.        
  95.  
  96.  
  97.  
  98.        
  99.  
  100.  
  101.  
  102.         #Add Contents for GroupBox - Non-Exempt
  103.  
  104.         $groupboxNonExempt.Controls.Add($listboxNonExempt)
  105.  
  106.  
  107.         #Add Contents for GroupBox - Name
  108.         $groupboxName.Controls.Add($comboboxNameSearch)
  109.         $groupboxName.Controls.Add($bnFind)
  110.      
  111.         $groupboxName.Controls.Add($groupboxNonExempt)
  112.  
  113.         $groupboxName.Controls.Add($bnCancelForm)
  114.         $groupboxName.Controls.Add($bnOKForm)
  115.        
  116.  
  117.         #Add to Panel
  118.         $formPanel.Controls.Add($groupboxName)
  119.  
  120.  
  121.  
  122.         #Form1
  123.        
  124.         $Form = New-Object System.Windows.Forms.Form
  125.         $Form.ClientSize = New-Object System.Drawing.Size(464, 386)
  126.         $Form.Controls.Add($formPanel)
  127.         $Form.Text = "New Hires Form"
  128.         $Form.CancelButton = $bnCancelForm
  129.         #$Form.AcceptButton = $bnOKForm
  130.         $Form.MaximizeBox = $false
  131.         $Form.SizeGripStyle = 'Hide'
  132.         $Form.MaximumSize = New-Object System.Drawing.Size (480,386)
  133.         $Form.MinimumSize = New-Object System.Drawing.Size (480,386)
  134.      
  135.        
  136.  
  137. #Form 1 End
  138. #--------------------------------------------------------------------------
  139. #Form 2 Start
  140.  
  141.  
  142.        
  143.         #Button OK
  144.        
  145.         $buttonOK = New-Object System.Windows.Forms.Button
  146.         $buttonOK.Location = New-Object System.Drawing.Point(333, 273)
  147.         $buttonOK.Size = New-Object System.Drawing.Size(75, 23)
  148.         $buttonOK.Text = "OK"
  149.         $buttonOK.UseVisualStyleBackColor = $True
  150.  
  151.        
  152.  
  153.  
  154.         #Form2 - Account Details
  155.        
  156.         $Form2 = New-Object System.Windows.Forms.Form
  157.         $Form2.ClientSize = New-Object System.Drawing.Size(449, 378)
  158.         $Form2.MaximizeBox = $false
  159.         $Form2.SizeGripStyle = 'Hide'        
  160.         $Form2.MaximumSize = New-Object System.Drawing.Size (449,378)
  161.         $Form2.MinimumSize = New-Object System.Drawing.Size (449,378)
  162.        
  163.  
  164.         $Form2.Controls.Add($buttonOK)
  165.  
  166.         $Form2.CancelButton = $buttonCancel
  167.         #$Form2.AcceptButton = $buttonOK
  168.  
  169.  
  170.         #$Form2.ShowDialog()
  171.  
  172. #Form 2 End
  173. #-------------------------------------------------------------------------------
  174.  
  175. #Search for users [Add to list]
  176. $bnFind.Add_Click({
  177.    
  178.    
  179.    
  180.  
  181.     #Sets all results to variable
  182.     $name = $comboboxNameSearch.Text
  183.  
  184.     #If variable is not empty, continue
  185.     if($name -ne ""){
  186.    
  187.            
  188.             #add to results list
  189.              
  190.                  
  191.             $listboxNonExempt.Items.Add($comboboxNameSearch.Text)
  192.  
  193.                              
  194.                              }
  195.    
  196.  
  197.                  })
  198.  
  199.  
  200.  
  201.  
  202. #Start script with OK
  203. $bnOKForm.Add_Click({
  204.  
  205. #For each name in list
  206. foreach($n in $listboxNonExempt.Items){
  207.    
  208.  
  209.  
  210.     $buttonOK.Add_Click({
  211.    
  212.     #Output current name in loop
  213.     Write-Host $n
  214.  
  215.     #Close the Form2
  216.     $Form2.close()
  217.  
  218.     })
  219.  
  220.  #Open a Form2 for each user in $listboxNonExempt  
  221.  $Form2.ShowDialog()
  222.    
  223.  
  224.  
  225.   }
  226.  
  227.  
  228.  
  229. })
  230.  
  231.  
  232.  
  233. #Open Form
  234. $Form.ShowDialog()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top