Advertisement
Guest User

Untitled

a guest
May 21st, 2018
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.54 KB | None | 0 0
  1. [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
  2. Function Mirror_UserFun
  3. {
  4. param([string]$MU=$args[0])
  5. $MirrorUser = Get-ADUser -identity $MU -properties memberof | select memberof
  6. }
  7. Function Create_User
  8. {
  9. New-ADUser -SamAccountName $samaccountname -Name $displayname -Office $LC -ChangePasswordAtLogon $true -Title $JT -AccountPassword $password
  10. ForEach ($group in $MirrorUser)
  11. {
  12. Add-ADGroupMember $group -Members $samaccountname
  13. }
  14. }
  15. $textboxsize = New-Object System.Drawing.Size (85,8)
  16. $labelsize = New-Object System.Drawing.Size(65,15)
  17.  
  18. $NewStarterForm = New-Object System.Windows.Forms.Form
  19. $NewStarterForm.Text = "New Start Form"
  20. $NewStarterForm.Size = New-Object System.Drawing.Size(300,500)
  21. $NewStarterForm.FormBorderStyle = "FixedDialog"
  22. $NewStarterForm.TopMost = $true
  23. $NewStarterForm.MaximizeBox = $false
  24. $NewStarterForm.MinimizeBox = $false
  25. $NewStarterForm.ControlBox = $true
  26. $NewStarterForm.KeyPreview = $True
  27. $NewStarterForm.StartPosition = "CenterScreen"
  28. $NewStarterForm.Font = "Segoe UI"
  29.  
  30. #firstname Label
  31. $FirstName_NewStarterForm = New-Object System.Windows.Forms.Label
  32. $FirstName_NewStarterForm.Location = New-Object System.Drawing.Size(8,8)
  33. $FirstName_NewStarterForm.Size = $labelsize
  34. $FirstName_NewStarterForm.TextAlign = "TopLeft"
  35. $FirstName_NewStarterForm.Text = "First Name :"
  36. $NewStarterForm.Controls.Add($FirstName_NewStarterForm)
  37. #firstname textbox
  38. $firstname_textbox = New-Object System.Windows.Forms.TextBox
  39. $firstname_textbox.Location = New-Object System.Drawing.Size (85,8)
  40. $firstname_textbox.Size = $textboxsize
  41. $firstname_textbox.TextAlign = "Left"
  42. $firstname_textbox.Text
  43. $NewStarterForm.Controls.Add($firstname_textbox)
  44.  
  45. #Initial Label
  46. $Intial_NewStarterForm = New-Object System.Windows.Forms.Label
  47. $Intial_NewStarterForm.Location = New-Object System.Drawing.Size(175,40)
  48. $Intial_NewStarterForm.Size = New-Object System.Drawing.Size(25,32)
  49. $Intial_NewStarterForm.TextAlign = "TopLeft"
  50. $Intial_NewStarterForm.Text = "In:"
  51. $NewStarterForm.Controls.Add($Intial_NewStarterForm)
  52.  
  53. #Initial textbox
  54. $Intitial_textbox = New-Object System.Windows.Forms.TextBox
  55. $Intitial_textbox.Location = New-Object System.Drawing.Size (200,40)
  56. $Intitial_textbox.Size = $textboxsize
  57. $Intitial_textbox.TextAlign = "Left"
  58. $Intitial_textbox.Text
  59. $NewStarterForm.Controls.Add($Intitial_textbox)
  60.  
  61. #Surname Label
  62. $Surname_NewStarterForm = New-Object System.Windows.Forms.Label
  63. $Surname_NewStarterForm.Location = New-Object System.Drawing.Size(10,44)
  64. $Surname_NewStarterForm.Size = $labelsize
  65. $Surname_NewStarterForm.TextAlign = "MiddleLeft"
  66. $Surname_NewStarterForm.Text = "Surname:"
  67. $NewStarterForm.Controls.Add($Surname_NewStarterForm)
  68.  
  69. #Surname textbox
  70. $Surname_textbox = New-Object System.Windows.Forms.TextBox
  71. $Surname_textbox.Location = New-Object System.Drawing.Size (85,40)
  72. $Surname_textbox.Size = $textboxsize
  73. $Surname_textbox.TextAlign = "Left"
  74. $Surname_textbox.Text
  75. $NewStarterForm.Controls.Add($Surname_textbox)
  76.  
  77. #Location Label
  78. $Location_NewStarterForm = New-Object System.Windows.Forms.Label
  79. $Location_NewStarterForm.Location = New-Object System.Drawing.Size(10,75)
  80. $Location_NewStarterForm.Size = $labelsize
  81. $Location_NewStarterForm.TextAlign = "BottomLeft"
  82. $Location_NewStarterForm.Text = "Location:"
  83. $NewStarterForm.Controls.Add($Location_NewStarterForm)
  84.  
  85. #Location textbox
  86. $Location_textbox = New-Object System.Windows.Forms.TextBox
  87. $Location_textbox.Location = New-Object System.Drawing.Size (85,70)
  88. $Location_textbox.Size = $textboxsize
  89. $Location_textbox.TextAlign = "Left"
  90. $Location_textbox.Text
  91. $NewStarterForm.Controls.Add($Location_textbox)
  92.  
  93. #Job Title Label
  94. $JobTitle_NewStarterForm = New-Object System.Windows.Forms.Label
  95. $JobTitle_NewStarterForm.Location = New-Object System.Drawing.Size(10,105)
  96. $JobTitle_NewStarterForm.Size = $labelsize
  97. $JobTitle_NewStarterForm.TextAlign = "BottomLeft"
  98. $JobTitle_NewStarterForm.Text = "Job Title:"
  99. $NewStarterForm.Controls.Add($JobTitle_NewStarterForm)
  100.  
  101. #Job Title textbox
  102. $JobTitle_textbox = New-Object System.Windows.Forms.TextBox
  103. $JobTitle_textbox.Location = New-Object System.Drawing.Size (85,100)
  104. $JobTitle_textbox.Size = $textboxsize
  105. $JobTitle_textbox.TextAlign = "Left"
  106. $JobTitle_textbox.Text
  107. $NewStarterForm.Controls.Add($JobTitle_textbox)
  108.  
  109. #Mirror Label
  110. $MirrorUser_NewStarterForm = New-Object System.Windows.Forms.Label
  111. $MirrorUser_NewStarterForm.Location = New-Object System.Drawing.Size(10,180)
  112. $MirrorUser_NewStarterForm.Size = $labelsize
  113. $MirrorUser_NewStarterForm.TextAlign = "BottomLeft"
  114. $MirrorUser_NewStarterForm.Text = "Mirror User:"
  115. $NewStarterForm.Controls.Add($MirrorUser_NewStarterForm)
  116.  
  117. #Mirror textbox
  118. $MirrorUser_textbox = New-Object System.Windows.Forms.TextBox
  119. $MirrorUser_textbox.Location = New-Object System.Drawing.Size (85,175)
  120. $MirrorUser_textbox.Size = $textboxsize
  121. $MirrorUser_textbox.TextAlign = "Left"
  122. $MirrorUser_textbox.Text
  123. $NewStarterForm.Controls.Add($MirrorUser_textbox)
  124.  
  125. #Mirror User Button
  126. $MirrorUser_Button = New-Object System.Windows.Forms.Button
  127. $MirrorUser_Button.Location = New-Object System.Drawing.Size(180,175)
  128. $MirrorUser_Button.Size = New-Object System.Drawing.Size(80,20)
  129. $MirrorUser_Button.Text = "Get User"
  130. $MirrorUser_Button.DialogResult = ([System.Windows.Forms.DialogResult]::OK1)
  131. $NewStarterForm.Controls.Add($MirrorUser_Button)
  132.  
  133.  
  134. #CreateUser Button
  135. $CreateUser_Button = New-Object System.Windows.Forms.Button
  136. $CreateUser_Button.Location = New-Object System.Drawing.Size(180,205)
  137. $CreateUser_Button.Size = New-Object System.Drawing.Size(80,20)
  138. $CreateUser_Button.Text = "Create User"
  139. $CreateUser_Button.DialogResult = ([System.Windows.Forms.DialogResult]::OK)
  140. $NewStarterForm.Controls.Add($CreateUser_Button)
  141. #HomeDrive Creation
  142.  
  143. #Return Results + show form
  144. $NewStarterForm.Add_Shown({$NewStarterForm.Activate()})
  145. $result = $NewStarterForm.ShowDialog()
  146. if ($result -eq [System.Windows.Forms.DialogResult]::retry)
  147. {
  148. $mirroruserinfo = Mirror_UserFun $mirroruser_textbox.Text
  149. $FN = $firstname_textbox.Text
  150. $SN = $Surname_textbox.Text
  151. $IN = $Intitial_textbox.text
  152. $LC = $Location_textbox.Text
  153. $JT = $JobTitle_textbox.Text
  154.  
  155. }
  156.  
  157. $samaccountname = $SN + $IN
  158. $displayname = $FN + $SN
  159. $password = 'Thursday.1'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement