Guest User

password reset tool

a guest
Jun 25th, 2013
579
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.10 KB | None | 0 0
  1. ####################################################################################################################################
  2. # Script name: password reset tool
  3. # purpose of script: to allow staff members to reset a students password from their laptop in classroom
  4. # Date of creation: 23/05/2013
  5. # Version Number: 1.0
  6. # Author: conor bryant
  7. #
  8. ####################################################################################################################################
  9.  
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17. [void][reflection.assembly]::Load("mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
  18. [void][reflection.assembly]::Load("System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
  19. [void][reflection.assembly]::Load("System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
  20. [void][reflection.assembly]::Load("System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
  21. [void][reflection.assembly]::Load("System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")
  22. [void][reflection.assembly]::Load("System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
  23. [void][reflection.assembly]::Load("System.DirectoryServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")
  24. [void][reflection.assembly]::Load("System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
  25. [void][reflection.assembly]::Load("System.ServiceProcess, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")
  26. [void][reflection.assembly]::Load("System.Windows.Forms.DataVisualization, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35")
  27.  
  28.  
  29. $Form = New-Object System.Windows.Forms.Form
  30. $Form.Size = New-Object System.Drawing.Size(367,345)
  31. $form.MaximumSize = '367, 345'
  32. $form.MinimumSize = '367, 345'
  33.  
  34. ############################################## Start functions
  35.  
  36. function gtfo
  37. {
  38. $form.close()
  39. }
  40.  
  41.  
  42.  
  43. function Reset-StudentPassword
  44. {
  45. Import-Module activedirectory
  46. $studentID=$DropDownBox.SelectedItem.ToString()
  47. if ($studentID -eq $null)
  48. {
  49. [System.Reflection.Assembly]::LoadWithPartialName(“System.Windows.Forms”)
  50. [Windows.Forms.MessageBox]::Show(
  51. “You have not selected a Student
  52. please select a student and try again”, “Invalid Student”, [Windows.Forms.MessageBoxButtons]::OK, [Windows.Forms.MessageBoxIcon]::Stop)
  53. }
  54. elseif(($Birthdate = get-aduser -identity $StudentID -Properties fax | Select-Object fax | foreach { $_.fax } | ConvertTo-SecureString -AsPlainText -Force) -eq $null)
  55. {[System.Reflection.Assembly]::LoadWithPartialName(“System.Windows.Forms”)
  56. [Windows.Forms.MessageBox]::Show(
  57. “The students password revovery has not been configured
  58. Please contact your network administrator”, "Password recovery error”, [Windows.Forms.MessageBoxButtons]::OK, [Windows.Forms.MessageBoxIcon]::Stop)
  59. }
  60. else
  61. {
  62. $Birthdate = get-aduser -identity $StudentID -Properties fax | Select-Object fax | foreach { $_.fax } | ConvertTo-SecureString -AsPlainText -Force
  63. set-ADAccountPassword -Identity $studentID -NewPassword $Birthdate -reset
  64. Enable-ADAccount -identity $studentID
  65. #set-ADUser -Identity $studentID -Enabled 1 #-ChangePasswordAtLogon 1 -PasswordNeverExpires 0
  66.  
  67.  
  68. [System.Reflection.Assembly]::LoadWithPartialName(“System.Windows.Forms”)
  69. [Windows.Forms.MessageBox]::Show(
  70. “ The password for $studentID has been reset to their bithday
  71. and will need to change their password after they login
  72.  
  73. ”, “Succesful password reset”, [Windows.Forms.MessageBoxButtons]::OK, [Windows.Forms.MessageBoxIcon]::information)
  74.  
  75. }
  76.  
  77. Clear-Variable -name studentID
  78. }
  79.  
  80.  
  81. function Get-Students
  82. {
  83. Import-Module activedirectory
  84. $year12 = (get-date).year
  85. $year11 = $year12 + 1
  86. $year10 = $year11 + 1
  87. $year09 = $year10 + 1
  88. $year08 = $year09 + 1
  89. $year07 = $year08 + 1
  90. $year12OU = ('ou=' + $year12 + ',OU=Users,OU=Students,OU=Parkdale_Secondary_College,DC=curric,DC=parkdale-sc,DC=wan')
  91. $year11OU = ('ou=' + $year11 + ',OU=Users,OU=Students,OU=Parkdale_Secondary_College,DC=curric,DC=parkdale-sc,DC=wan')
  92. $year10OU = ('ou=' + $year10 + ',OU=Users,OU=Students,OU=Parkdale_Secondary_College,DC=curric,DC=parkdale-sc,DC=wan')
  93. $year09OU = ('ou=' + $year09 + ',OU=Users,OU=Students,OU=Parkdale_Secondary_College,DC=curric,DC=parkdale-sc,DC=wan')
  94. $year08OU = ('ou=' + $year08 + ',OU=Users,OU=Students,OU=Parkdale_Secondary_College,DC=curric,DC=parkdale-sc,DC=wan')
  95. $year07OU = ('ou=' + $year07 + ',OU=Users,OU=Students,OU=Parkdale_Secondary_College,DC=curric,DC=parkdale-sc,DC=wan')
  96. $year12Students = get-aduser -Filter * -searchbase $year12OU | Select-Object -Property samaccountname | Sort-Object -Property samaccountname
  97. $year11Students = get-aduser -Filter * -searchbase $year11OU | Select-Object -Property samaccountname | Sort-Object -Property samaccountname
  98. $year10Students = get-aduser -Filter * -searchbase $year10OU | Select-Object -Property samaccountname | Sort-Object -Property samaccountname
  99. $year09Students = get-aduser -Filter * -searchbase $year09OU | Select-Object -Property samaccountname | Sort-Object -Property samaccountname
  100. $year08Students = get-aduser -Filter * -searchbase $year08OU | Select-Object -Property samaccountname | Sort-Object -Property samaccountname
  101. $year07Students = get-aduser -Filter * -searchbase $year07OU | Select-Object -Property samaccountname | Sort-Object -Property samaccountname
  102. $activeacounts = $year12Students + $year11Students + $year10Students + $year09Students + $year08Students + $year07Students | foreach { $_.samaccountname } | sort-object
  103. $activeacounts
  104. }
  105.  
  106.  
  107. function student-info
  108. {
  109. $studentID=$DropDownBox.SelectedItem.ToString()
  110.  
  111. $textboxfirstname.text = get-aduser -identity $StudentID -Properties GivenName | Select-Object | foreach { $_.GivenName }
  112. $textboxsurname.text = get-aduser -identity $StudentID -Properties Surname | Select-Object | foreach { $_.Surname }
  113. $textboxformgroup.text = get-aduser -identity $StudentID -Properties Division | Select-Object | foreach { $_.Division }
  114.  
  115.  
  116.  
  117. }
  118.  
  119.  
  120.  
  121.  
  122. ############################################## end functions
  123.  
  124. ############################################## Start drop down boxes
  125.  
  126. $DropDownBox = New-Object System.Windows.Forms.ComboBox
  127. $DropDownBox.Location = New-Object System.Drawing.Size(112,147)
  128. $DropDownBox.Size = New-Object System.Drawing.Size(110,201)
  129. $DropDownBox.DropDownHeight = 200
  130. $DropDownBox.add_SelectedValueChanged({student-info})
  131. $Form.Controls.Add($DropDownBox)
  132. $DropDownBox.Text = "Select a Student"
  133. $Studentlist = Get-Students
  134.  
  135. foreach ($student in $Studentlist) {
  136. $DropDownBox.Items.Add($Student)
  137. } #end foreach
  138.  
  139.  
  140. ############################################## end drop down boxes
  141.  
  142. ############################################## Start label fields
  143.  
  144.  
  145. # labelParkdaleSecondaryCol
  146. #
  147. $labelParkdaleSecondaryCol = New-Object 'System.Windows.Forms.Label'
  148. $labelParkdaleSecondaryCol.Font = "Microsoft Sans Serif, 15pt, style=Bold"
  149. $labelParkdaleSecondaryCol.Location = '0, 0'
  150. $labelParkdaleSecondaryCol.Name = "labelParkdaleSecondaryCol"
  151. $labelParkdaleSecondaryCol.Size = '350, 90'
  152. $labelParkdaleSecondaryCol.TabIndex = 12
  153. $labelParkdaleSecondaryCol.Text = "Parkdale Secondary College Password Reset Tool"
  154. $labelParkdaleSecondaryCol.TextAlign = 'MiddleCenter'
  155. $form.Controls.Add($labelParkdaleSecondaryCol)
  156. #
  157. # labelStudentDetails
  158. #
  159. $labelStudentDetails = New-Object 'System.Windows.Forms.Label'
  160. $labelStudentDetails.Font = "Microsoft Sans Serif, 10pt"
  161. $labelStudentDetails.Location = '14, 171'
  162. $labelStudentDetails.Name = "labelStudentDetails"
  163. $labelStudentDetails.Size = '208, 23'
  164. $labelStudentDetails.TabIndex = 11
  165. $labelStudentDetails.Text = "Student Details"
  166. $labelStudentDetails.TextAlign = 'MiddleCenter'
  167. $form.Controls.Add($labelStudentDetails)
  168. #
  169. # labelUseTheDropDownBoxToS
  170. #
  171. $labelUseTheDropDownBoxToS = New-Object 'System.Windows.Forms.Label'
  172. $labelUseTheDropDownBoxToS.Font = "Microsoft Sans Serif, 10pt"
  173. $labelUseTheDropDownBoxToS.Location = '14, 93'
  174. $labelUseTheDropDownBoxToS.Name = "labelUseTheDropDownBoxToS"
  175. $labelUseTheDropDownBoxToS.Size = '208, 40'
  176. $labelUseTheDropDownBoxToS.TabIndex = 10
  177. $labelUseTheDropDownBoxToS.Text = "Use the drop down box to select a student"
  178. $labelUseTheDropDownBoxToS.TextAlign = 'MiddleCenter'
  179. $form.Controls.Add($labelUseTheDropDownBoxToS)
  180. #
  181. # labelFormGroup
  182. #
  183. $labelFormGroup = New-Object 'System.Windows.Forms.Label'
  184. $labelFormGroup.Location = '14, 247'
  185. $labelFormGroup.Name = "labelFormGroup"
  186. $labelFormGroup.Size = '80, 23'
  187. $labelFormGroup.TabIndex = 6
  188. $labelFormGroup.Text = "Form Group:"
  189. $form.Controls.Add($labelFormGroup)
  190. #
  191. # labelSurname
  192. #
  193. $labelSurname = New-Object 'System.Windows.Forms.Label'
  194. $labelSurname.Location = '14, 224'
  195. $labelSurname.Name = "labelSurname"
  196. $labelSurname.Size = '80, 23'
  197. $labelSurname.TabIndex = 5
  198. $labelSurname.Text = "Surname:"
  199. $form.Controls.Add($labelSurname)
  200. #
  201. # labelFirstName
  202. #
  203. $labelFirstName = New-Object 'System.Windows.Forms.Label'
  204. $labelFirstName.Location = '14, 201'
  205. $labelFirstName.Name = "labelFirstName"
  206. $labelFirstName.Size = '80, 23'
  207. $labelFirstName.TabIndex = 4
  208. $labelFirstName.Text = "First Name:"
  209. $form.Controls.Add($labelFirstName)
  210. #
  211. # labelStudentcode
  212. #
  213. $labelStudentcode = New-Object 'System.Windows.Forms.Label'
  214. $labelStudentcode.Location = '14, 150'
  215. $labelStudentcode.Name = "labelStudentcode"
  216. $labelStudentcode.Size = '80, 23'
  217. $labelStudentcode.TabIndex = 3
  218. $labelStudentcode.Text = "Student Code:"
  219. $form.Controls.Add($labelStudentcode)
  220. #
  221.  
  222.  
  223. ############################################## end label fields
  224.  
  225. ############################################## Start text fields
  226.  
  227. # textboxformgroup
  228. #
  229.  
  230. $textboxformgroup = New-Object 'System.Windows.Forms.TextBox'
  231. $textboxformgroup.Location = '112, 250'
  232. $textboxformgroup.Name = "textboxformgroup"
  233. $textboxformgroup.Size = '110, 20'
  234. $form.Controls.Add($textboxformgroup)
  235.  
  236. #
  237. # textboxsurname
  238. #
  239. $textboxsurname = New-Object 'System.Windows.Forms.TextBox'
  240. $textboxsurname.Location = '112, 227'
  241. $textboxsurname.Name = "textboxsurname"
  242. $textboxsurname.Size = '110, 20'
  243. $form.Controls.Add($textboxsurname)
  244.  
  245. #
  246. # textboxfirstname
  247. #
  248. $textboxfirstname = New-Object 'System.Windows.Forms.TextBox'
  249. $textboxfirstname.Location = '112, 204'
  250. $textboxfirstname.Name = "textboxfirstname"
  251. $textboxfirstname.Size = '110, 20'
  252. $form.Controls.Add($textboxfirstname)
  253.  
  254.  
  255. ############################################## end text fields
  256.  
  257. ############################################## Start Links boxes
  258.  
  259. $linklabelForHelpUsingThisSoft = New-Object 'System.Windows.Forms.LinkLabel'
  260. $form.Controls.Add($linklabelForHelpUsingThisSoft)
  261. $linklabelForHelpUsingThisSoft.Location = '14, 279'
  262. $linklabelForHelpUsingThisSoft.Name = "linklabelForHelpUsingThisSoft"
  263. $linklabelForHelpUsingThisSoft.Size = '324, 23'
  264. $linklabelForHelpUsingThisSoft.Text = "For help using this software please click here."
  265. $linklabelForHelpUsingThisSoft.TextAlign = 'MiddleCenter'
  266. $form.Controls.Add($linklabelForHelpUsingThisSoft)
  267.  
  268.  
  269. ############################################## Start Links boxes
  270.  
  271. ############################################## Start buttons
  272.  
  273. $Button = New-Object System.Windows.Forms.Button
  274. $Button.Location = New-Object System.Drawing.Size(228,93)
  275. $Button.Size = New-Object System.Drawing.Size(110,80)
  276. $Button.Text = "Reset Password"
  277. $Button.Add_Click({Reset-StudentPassword})
  278. $Form.Controls.Add($Button)
  279.  
  280. $Button = New-Object System.Windows.Forms.Button
  281. $Button.Location = New-Object System.Drawing.Size(228,184)
  282. $Button.Size = New-Object System.Drawing.Size(110,80)
  283. $Button.Text = "Exit"
  284. $Button.Add_Click({gtfo})
  285. $Form.Controls.Add($Button)
  286.  
  287.  
  288. ############################################## end buttons
  289.  
  290. $Form.Add_Shown({$Form.Activate()})
  291. $form.Text = "Password Reset Tool"
  292. [void] $Form.ShowDialog()
Advertisement
Add Comment
Please, Sign In to add comment