Advertisement
Guest User

Untitled

a guest
May 25th, 2018
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.31 KB | None | 0 0
  1. [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
  2.  
  3. Function Create_User
  4. {
  5. $samaccountname = $Surname_textbox.Text + $Intitial_textbox.Text
  6. $displayname = ("$FN $SN")
  7. $password = "Thursday.1" | Convert-ToSecureString -AsPlainText -Force
  8. $FN = $firstname_textbox.Text
  9. $SN = $Surname_textbox.Text
  10. $IN = $Intitial_textbox.text
  11. $LC = $Location_textbox.Text
  12. $JT = $JobTitle_textbox.Text
  13. $mu = $MirrorUser_textbox.Text
  14. $HomeDriveCheckbox.checked
  15. $HomeDrive = 'H:'
  16. $userroot = 'C:\test\'
  17. $HomeDirectory= $userroot+ $samaccountname
  18. $HomeDirectory2 = $HomeDirectory + "\Documents"
  19. $email = $DropdownOptions.SelectedItem
  20.  
  21. Get-ADUser -identity $samaccountname
  22. If ($samaccountname -eq $true)
  23. {
  24.  
  25. }
  26.  
  27. New-ADUser -Name "$FN $SN" -UserPrincipalName "$Samaccountname@test.local" -SamAccountName $samaccountname -GivenName $FN -Surname $SN -DisplayName "$FN $SN" -Office $LC -ChangePasswordAtLogon $true -Title $JT -AccountPassword $password -Enabled $true -EmailAddress "$FN.$SN$email"
  28. $members = Get-ADUser -Identity $mu -Properties Memberof | Select-object -ExpandProperty Memberof | Get-ADGroup -Properties name
  29. foreach ($group in $members)
  30. {
  31. Add-ADGroupMember -Identity $group.name -Members $samaccountname
  32. }
  33. If ($HomeDriveCheckbox.checked -eq $true)
  34. {
  35. New-Item $userroot -Name $samaccountname -ItemType Directory
  36. $rights = [System.Security.AccessControl.FileSystemRights]::Read -bor [System.Security.AccessControl.FileSystemRights]::Write -bor [System.Security.AccessControl.FileSystemRights]::Modify -bor [System.Security.AccessControl.FileSystemRights]::FullControl
  37. $inherit = [System.Security.AccessControl.InheritanceFlags]::ContainerInherit -bor [System.Security.AccessControl.InheritanceFlags]::ObjectInherit
  38. $propagation = [System.Security.AccessControl.PropagationFlags]::None
  39. $access = [System.Security.AccessControl.AccessControlType]::Allow
  40. $accessrule = New-Object System.Security.AccessControl.FileSystemAccessRule("$samaccountname",$rights,$inherit,$propagation,$access)
  41. $acl = Get-Acl $HomeDirectory
  42. $acl.AddAccessRule($accessrule)
  43. $account = New-Object System.Security.Principal.NTAccount($samaccountname)
  44. $acl.SetOwner("builtin\Administrator")
  45. $acl.SetAccessRule($accessrule)
  46. Set-Acl $HomeDirectory $acl
  47. New-item $HomeDirectory -Name "Documents" -ItemType Directory
  48. Set-ADUser -Identity $samaccountname -HomeDrive $HomeDrive -HomeDirectory $HomeDirectory2
  49. }
  50. }
  51. $textboxsize = New-Object System.Drawing.Size (85,8)
  52. $labelsize = New-Object System.Drawing.Size(65,15)
  53.  
  54. $NewStarterForm = New-Object System.Windows.Forms.Form
  55. $NewStarterForm.Text = "New Start Form"
  56. $NewStarterForm.Size = New-Object System.Drawing.Size(300,500)
  57. $NewStarterForm.FormBorderStyle = "FixedDialog"
  58. $NewStarterForm.TopMost = $true
  59. $NewStarterForm.MaximizeBox = $false
  60. $NewStarterForm.MinimizeBox = $false
  61. $NewStarterForm.ControlBox = $true
  62. $NewStarterForm.KeyPreview = $True
  63. $NewStarterForm.StartPosition = "CenterScreen"
  64. $NewStarterForm.Font = "Segoe UI"
  65.  
  66. #firstname Label
  67. $FirstName_NewStarterForm = New-Object System.Windows.Forms.Label
  68. $FirstName_NewStarterForm.Location = New-Object System.Drawing.Size(8,8)
  69. $FirstName_NewStarterForm.Size = $labelsize
  70. $FirstName_NewStarterForm.TextAlign = "TopLeft"
  71. $FirstName_NewStarterForm.Text = "First Name :"
  72. $NewStarterForm.Controls.Add($FirstName_NewStarterForm)
  73. #firstname textbox
  74. $firstname_textbox = New-Object System.Windows.Forms.TextBox
  75. $firstname_textbox.Location = New-Object System.Drawing.Size (85,8)
  76. $firstname_textbox.Size = $textboxsize
  77. $firstname_textbox.TextAlign = "Left"
  78. $NewStarterForm.Controls.Add($firstname_textbox)
  79.  
  80. #Initial Label
  81. $Intial_NewStarterForm = New-Object System.Windows.Forms.Label
  82. $Intial_NewStarterForm.Location = New-Object System.Drawing.Size(175,40)
  83. $Intial_NewStarterForm.Size = New-Object System.Drawing.Size(25,32)
  84. $Intial_NewStarterForm.TextAlign = "TopLeft"
  85. $Intial_NewStarterForm.Text = "In:"
  86. $NewStarterForm.Controls.Add($Intial_NewStarterForm)
  87.  
  88. #Initial textbox
  89. $Intitial_textbox = New-Object System.Windows.Forms.TextBox
  90. $Intitial_textbox.Location = New-Object System.Drawing.Size (200,40)
  91. $Intitial_textbox.Size = $textboxsize
  92. $Intitial_textbox.TextAlign = "Left"
  93. $NewStarterForm.Controls.Add($Intitial_textbox)
  94.  
  95. #Surname Label
  96. $Surname_NewStarterForm = New-Object System.Windows.Forms.Label
  97. $Surname_NewStarterForm.Location = New-Object System.Drawing.Size(10,44)
  98. $Surname_NewStarterForm.Size = $labelsize
  99. $Surname_NewStarterForm.TextAlign = "MiddleLeft"
  100. $Surname_NewStarterForm.Text = "Surname:"
  101. $NewStarterForm.Controls.Add($Surname_NewStarterForm)
  102.  
  103. #Surname textbox
  104. $Surname_textbox = New-Object System.Windows.Forms.TextBox
  105. $Surname_textbox.Location = New-Object System.Drawing.Size (85,40)
  106. $Surname_textbox.Size = $textboxsize
  107. $Surname_textbox.TextAlign = "Left"
  108. $NewStarterForm.Controls.Add($Surname_textbox)
  109.  
  110. #Location Label
  111. $Location_NewStarterForm = New-Object System.Windows.Forms.Label
  112. $Location_NewStarterForm.Location = New-Object System.Drawing.Size(10,75)
  113. $Location_NewStarterForm.Size = $labelsize
  114. $Location_NewStarterForm.TextAlign = "BottomLeft"
  115. $Location_NewStarterForm.Text = "Location:"
  116. $NewStarterForm.Controls.Add($Location_NewStarterForm)
  117.  
  118. #Location textbox
  119. $Location_textbox = New-Object System.Windows.Forms.TextBox
  120. $Location_textbox.Location = New-Object System.Drawing.Size (85,70)
  121. $Location_textbox.Size = $textboxsize
  122. $Location_textbox.TextAlign = "Left"
  123. $NewStarterForm.Controls.Add($Location_textbox)
  124.  
  125. #Job Title Label
  126. $JobTitle_NewStarterForm = New-Object System.Windows.Forms.Label
  127. $JobTitle_NewStarterForm.Location = New-Object System.Drawing.Size(10,105)
  128. $JobTitle_NewStarterForm.Size = $labelsize
  129. $JobTitle_NewStarterForm.TextAlign = "BottomLeft"
  130. $JobTitle_NewStarterForm.Text = "Job Title:"
  131. $NewStarterForm.Controls.Add($JobTitle_NewStarterForm)
  132.  
  133. #Job Title textbox
  134. $JobTitle_textbox = New-Object System.Windows.Forms.TextBox
  135. $JobTitle_textbox.Location = New-Object System.Drawing.Size (85,100)
  136. $JobTitle_textbox.Size = $textboxsize
  137. $JobTitle_textbox.TextAlign = "Left"
  138. $NewStarterForm.Controls.Add($JobTitle_textbox)
  139.  
  140. ##HomeDrive Checkbox
  141. $HomeDriveCheckbox = New-Object System.Windows.Forms.CheckBox
  142. $HomeDriveCheckbox.Location = New-Object System.Drawing.Size(250,75)
  143. $HomeDriveCheckbox.Size = New-Object System.Drawing.Size(20,20)
  144. $HomeDriveCheckbox.TabIndex = 4
  145. $NewStarterForm.Controls.Add($HomeDriveCheckbox)
  146.  
  147. #HomeDrive Label
  148. $HomeDriveLabel = New-Object System.Windows.Forms.Label
  149. $HomeDriveLabel.Location = New-Object System.Drawing.Size (175,75)
  150. $HomeDriveLabel.Size = New-Object System.Drawing.Size(75,15)
  151. $HomeDriveLabel.Text ="Home Drive ?"
  152. $NewStarterForm.Controls.Add($HomeDriveLabel)
  153.  
  154. #Dropdown Label
  155. $DropdownLabel = New-Object System.Windows.Forms.Label
  156. $DropdownLabel.Location = New-Object System.Drawing.Size(10,125)
  157. $DropdownLabel.Size = New-Object System.Drawing.Size(250,15)
  158. $DropdownLabel.TextAlign = "BottomLeft"
  159. $DropdownLabel.Text = "Please pick OPS code from the list below:"
  160. $NewStarterForm.Controls.Add($DropdownLabel)
  161.  
  162.  
  163.  
  164.  
  165. #Dropdown Options
  166. $DropdownOptions = New-Object System.Windows.Forms.ListBox
  167. $DropdownOptions.Location = New-Object System.Drawing.Size(10,145)
  168. $DropdownOptions.Size = New-Object System.Drawing.Size(250,35)
  169. [void] $DropdownOptions.Items.Add('@test1.co.uk')
  170. [void] $DropdownOptions.Items.Add('@test2.co.uk')
  171. [void] $DropdownOptions.Items.Add('@test3.co.uk')
  172. [void] $DropdownOptions.Items.Add('@test4.co.uk')
  173. [void] $DropdownOptions.Items.Add('@test5.co.uk')
  174. [void] $DropdownOptions.Items.Add('@test6.co.uk')
  175. $NewStarterForm.Controls.Add($DropdownOptions)
  176.  
  177.  
  178.  
  179. #Mirror Label
  180. $MirrorUser_NewStarterForm = New-Object System.Windows.Forms.Label
  181. $MirrorUser_NewStarterForm.Location = New-Object System.Drawing.Size(10,180)
  182. $MirrorUser_NewStarterForm.Size = $labelsize
  183. $MirrorUser_NewStarterForm.TextAlign = "BottomLeft"
  184. $MirrorUser_NewStarterForm.Text = "Mirror User:"
  185. $NewStarterForm.Controls.Add($MirrorUser_NewStarterForm)
  186.  
  187. #Mirror textbox
  188. $MirrorUser_textbox = New-Object System.Windows.Forms.TextBox
  189. $MirrorUser_textbox.Location = New-Object System.Drawing.Size (85,175)
  190. $MirrorUser_textbox.Size = $textboxsize
  191. $MirrorUser_textbox.TextAlign = "Left"
  192. $NewStarterForm.Controls.Add($MirrorUser_textbox)
  193.  
  194. #CreateUser Button
  195. $CreateUser_Button = New-Object System.Windows.Forms.Button
  196. $CreateUser_Button.Location = New-Object System.Drawing.Size(180,205)
  197. $CreateUser_Button.Size = New-Object System.Drawing.Size(80,20)
  198. $CreateUser_Button.Text = "Create User"
  199. $CreateUser_Button.add_click({Create_User})
  200. $NewStarterForm.Controls.Add($CreateUser_Button)
  201. #HomeDrive Creation
  202.  
  203. #Return Results + show form
  204. $NewStarterForm.Add_Shown({$NewStarterForm.Activate()})
  205. $result = $NewStarterForm.ShowDialog()
  206. return
  207. $FN = $firstname_textbox.Text, $SN = $Surname_textbox.Text, $IN = $Intitial_textbox.text, $LC = $Location_textbox.Text, $JT = $JobTitle_textbox.Text
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement