Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ####################################################################################################################################
- # Script name: password reset tool
- # purpose of script: to allow staff members to reset a students password from their laptop in classroom
- # Date of creation: 23/05/2013
- # Version Number: 1.0
- # Author: conor bryant
- #
- ####################################################################################################################################
- [void][reflection.assembly]::Load("mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
- [void][reflection.assembly]::Load("System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
- [void][reflection.assembly]::Load("System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
- [void][reflection.assembly]::Load("System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
- [void][reflection.assembly]::Load("System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")
- [void][reflection.assembly]::Load("System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
- [void][reflection.assembly]::Load("System.DirectoryServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")
- [void][reflection.assembly]::Load("System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
- [void][reflection.assembly]::Load("System.ServiceProcess, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")
- [void][reflection.assembly]::Load("System.Windows.Forms.DataVisualization, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35")
- $Form = New-Object System.Windows.Forms.Form
- $Form.Size = New-Object System.Drawing.Size(367,345)
- $form.MaximumSize = '367, 345'
- $form.MinimumSize = '367, 345'
- ############################################## Start functions
- function gtfo
- {
- $form.close()
- }
- function Reset-StudentPassword
- {
- Import-Module activedirectory
- $studentID=$DropDownBox.SelectedItem.ToString()
- if ($studentID -eq $null)
- {
- [System.Reflection.Assembly]::LoadWithPartialName(“System.Windows.Forms”)
- [Windows.Forms.MessageBox]::Show(
- “You have not selected a Student
- please select a student and try again”, “Invalid Student”, [Windows.Forms.MessageBoxButtons]::OK, [Windows.Forms.MessageBoxIcon]::Stop)
- }
- elseif(($Birthdate = get-aduser -identity $StudentID -Properties fax | Select-Object fax | foreach { $_.fax } | ConvertTo-SecureString -AsPlainText -Force) -eq $null)
- {[System.Reflection.Assembly]::LoadWithPartialName(“System.Windows.Forms”)
- [Windows.Forms.MessageBox]::Show(
- “The students password revovery has not been configured
- Please contact your network administrator”, "Password recovery error”, [Windows.Forms.MessageBoxButtons]::OK, [Windows.Forms.MessageBoxIcon]::Stop)
- }
- else
- {
- $Birthdate = get-aduser -identity $StudentID -Properties fax | Select-Object fax | foreach { $_.fax } | ConvertTo-SecureString -AsPlainText -Force
- set-ADAccountPassword -Identity $studentID -NewPassword $Birthdate -reset
- Enable-ADAccount -identity $studentID
- #set-ADUser -Identity $studentID -Enabled 1 #-ChangePasswordAtLogon 1 -PasswordNeverExpires 0
- [System.Reflection.Assembly]::LoadWithPartialName(“System.Windows.Forms”)
- [Windows.Forms.MessageBox]::Show(
- “ The password for $studentID has been reset to their bithday
- and will need to change their password after they login
- ”, “Succesful password reset”, [Windows.Forms.MessageBoxButtons]::OK, [Windows.Forms.MessageBoxIcon]::information)
- }
- Clear-Variable -name studentID
- }
- function Get-Students
- {
- Import-Module activedirectory
- $year12 = (get-date).year
- $year11 = $year12 + 1
- $year10 = $year11 + 1
- $year09 = $year10 + 1
- $year08 = $year09 + 1
- $year07 = $year08 + 1
- $year12OU = ('ou=' + $year12 + ',OU=Users,OU=Students,OU=Parkdale_Secondary_College,DC=curric,DC=parkdale-sc,DC=wan')
- $year11OU = ('ou=' + $year11 + ',OU=Users,OU=Students,OU=Parkdale_Secondary_College,DC=curric,DC=parkdale-sc,DC=wan')
- $year10OU = ('ou=' + $year10 + ',OU=Users,OU=Students,OU=Parkdale_Secondary_College,DC=curric,DC=parkdale-sc,DC=wan')
- $year09OU = ('ou=' + $year09 + ',OU=Users,OU=Students,OU=Parkdale_Secondary_College,DC=curric,DC=parkdale-sc,DC=wan')
- $year08OU = ('ou=' + $year08 + ',OU=Users,OU=Students,OU=Parkdale_Secondary_College,DC=curric,DC=parkdale-sc,DC=wan')
- $year07OU = ('ou=' + $year07 + ',OU=Users,OU=Students,OU=Parkdale_Secondary_College,DC=curric,DC=parkdale-sc,DC=wan')
- $year12Students = get-aduser -Filter * -searchbase $year12OU | Select-Object -Property samaccountname | Sort-Object -Property samaccountname
- $year11Students = get-aduser -Filter * -searchbase $year11OU | Select-Object -Property samaccountname | Sort-Object -Property samaccountname
- $year10Students = get-aduser -Filter * -searchbase $year10OU | Select-Object -Property samaccountname | Sort-Object -Property samaccountname
- $year09Students = get-aduser -Filter * -searchbase $year09OU | Select-Object -Property samaccountname | Sort-Object -Property samaccountname
- $year08Students = get-aduser -Filter * -searchbase $year08OU | Select-Object -Property samaccountname | Sort-Object -Property samaccountname
- $year07Students = get-aduser -Filter * -searchbase $year07OU | Select-Object -Property samaccountname | Sort-Object -Property samaccountname
- $activeacounts = $year12Students + $year11Students + $year10Students + $year09Students + $year08Students + $year07Students | foreach { $_.samaccountname } | sort-object
- $activeacounts
- }
- function student-info
- {
- $studentID=$DropDownBox.SelectedItem.ToString()
- $textboxfirstname.text = get-aduser -identity $StudentID -Properties GivenName | Select-Object | foreach { $_.GivenName }
- $textboxsurname.text = get-aduser -identity $StudentID -Properties Surname | Select-Object | foreach { $_.Surname }
- $textboxformgroup.text = get-aduser -identity $StudentID -Properties Division | Select-Object | foreach { $_.Division }
- }
- ############################################## end functions
- ############################################## Start drop down boxes
- $DropDownBox = New-Object System.Windows.Forms.ComboBox
- $DropDownBox.Location = New-Object System.Drawing.Size(112,147)
- $DropDownBox.Size = New-Object System.Drawing.Size(110,201)
- $DropDownBox.DropDownHeight = 200
- $DropDownBox.add_SelectedValueChanged({student-info})
- $Form.Controls.Add($DropDownBox)
- $DropDownBox.Text = "Select a Student"
- $Studentlist = Get-Students
- foreach ($student in $Studentlist) {
- $DropDownBox.Items.Add($Student)
- } #end foreach
- ############################################## end drop down boxes
- ############################################## Start label fields
- # labelParkdaleSecondaryCol
- #
- $labelParkdaleSecondaryCol = New-Object 'System.Windows.Forms.Label'
- $labelParkdaleSecondaryCol.Font = "Microsoft Sans Serif, 15pt, style=Bold"
- $labelParkdaleSecondaryCol.Location = '0, 0'
- $labelParkdaleSecondaryCol.Name = "labelParkdaleSecondaryCol"
- $labelParkdaleSecondaryCol.Size = '350, 90'
- $labelParkdaleSecondaryCol.TabIndex = 12
- $labelParkdaleSecondaryCol.Text = "Parkdale Secondary College Password Reset Tool"
- $labelParkdaleSecondaryCol.TextAlign = 'MiddleCenter'
- $form.Controls.Add($labelParkdaleSecondaryCol)
- #
- # labelStudentDetails
- #
- $labelStudentDetails = New-Object 'System.Windows.Forms.Label'
- $labelStudentDetails.Font = "Microsoft Sans Serif, 10pt"
- $labelStudentDetails.Location = '14, 171'
- $labelStudentDetails.Name = "labelStudentDetails"
- $labelStudentDetails.Size = '208, 23'
- $labelStudentDetails.TabIndex = 11
- $labelStudentDetails.Text = "Student Details"
- $labelStudentDetails.TextAlign = 'MiddleCenter'
- $form.Controls.Add($labelStudentDetails)
- #
- # labelUseTheDropDownBoxToS
- #
- $labelUseTheDropDownBoxToS = New-Object 'System.Windows.Forms.Label'
- $labelUseTheDropDownBoxToS.Font = "Microsoft Sans Serif, 10pt"
- $labelUseTheDropDownBoxToS.Location = '14, 93'
- $labelUseTheDropDownBoxToS.Name = "labelUseTheDropDownBoxToS"
- $labelUseTheDropDownBoxToS.Size = '208, 40'
- $labelUseTheDropDownBoxToS.TabIndex = 10
- $labelUseTheDropDownBoxToS.Text = "Use the drop down box to select a student"
- $labelUseTheDropDownBoxToS.TextAlign = 'MiddleCenter'
- $form.Controls.Add($labelUseTheDropDownBoxToS)
- #
- # labelFormGroup
- #
- $labelFormGroup = New-Object 'System.Windows.Forms.Label'
- $labelFormGroup.Location = '14, 247'
- $labelFormGroup.Name = "labelFormGroup"
- $labelFormGroup.Size = '80, 23'
- $labelFormGroup.TabIndex = 6
- $labelFormGroup.Text = "Form Group:"
- $form.Controls.Add($labelFormGroup)
- #
- # labelSurname
- #
- $labelSurname = New-Object 'System.Windows.Forms.Label'
- $labelSurname.Location = '14, 224'
- $labelSurname.Name = "labelSurname"
- $labelSurname.Size = '80, 23'
- $labelSurname.TabIndex = 5
- $labelSurname.Text = "Surname:"
- $form.Controls.Add($labelSurname)
- #
- # labelFirstName
- #
- $labelFirstName = New-Object 'System.Windows.Forms.Label'
- $labelFirstName.Location = '14, 201'
- $labelFirstName.Name = "labelFirstName"
- $labelFirstName.Size = '80, 23'
- $labelFirstName.TabIndex = 4
- $labelFirstName.Text = "First Name:"
- $form.Controls.Add($labelFirstName)
- #
- # labelStudentcode
- #
- $labelStudentcode = New-Object 'System.Windows.Forms.Label'
- $labelStudentcode.Location = '14, 150'
- $labelStudentcode.Name = "labelStudentcode"
- $labelStudentcode.Size = '80, 23'
- $labelStudentcode.TabIndex = 3
- $labelStudentcode.Text = "Student Code:"
- $form.Controls.Add($labelStudentcode)
- #
- ############################################## end label fields
- ############################################## Start text fields
- # textboxformgroup
- #
- $textboxformgroup = New-Object 'System.Windows.Forms.TextBox'
- $textboxformgroup.Location = '112, 250'
- $textboxformgroup.Name = "textboxformgroup"
- $textboxformgroup.Size = '110, 20'
- $form.Controls.Add($textboxformgroup)
- #
- # textboxsurname
- #
- $textboxsurname = New-Object 'System.Windows.Forms.TextBox'
- $textboxsurname.Location = '112, 227'
- $textboxsurname.Name = "textboxsurname"
- $textboxsurname.Size = '110, 20'
- $form.Controls.Add($textboxsurname)
- #
- # textboxfirstname
- #
- $textboxfirstname = New-Object 'System.Windows.Forms.TextBox'
- $textboxfirstname.Location = '112, 204'
- $textboxfirstname.Name = "textboxfirstname"
- $textboxfirstname.Size = '110, 20'
- $form.Controls.Add($textboxfirstname)
- ############################################## end text fields
- ############################################## Start Links boxes
- $linklabelForHelpUsingThisSoft = New-Object 'System.Windows.Forms.LinkLabel'
- $form.Controls.Add($linklabelForHelpUsingThisSoft)
- $linklabelForHelpUsingThisSoft.Location = '14, 279'
- $linklabelForHelpUsingThisSoft.Name = "linklabelForHelpUsingThisSoft"
- $linklabelForHelpUsingThisSoft.Size = '324, 23'
- $linklabelForHelpUsingThisSoft.Text = "For help using this software please click here."
- $linklabelForHelpUsingThisSoft.TextAlign = 'MiddleCenter'
- $form.Controls.Add($linklabelForHelpUsingThisSoft)
- ############################################## Start Links boxes
- ############################################## Start buttons
- $Button = New-Object System.Windows.Forms.Button
- $Button.Location = New-Object System.Drawing.Size(228,93)
- $Button.Size = New-Object System.Drawing.Size(110,80)
- $Button.Text = "Reset Password"
- $Button.Add_Click({Reset-StudentPassword})
- $Form.Controls.Add($Button)
- $Button = New-Object System.Windows.Forms.Button
- $Button.Location = New-Object System.Drawing.Size(228,184)
- $Button.Size = New-Object System.Drawing.Size(110,80)
- $Button.Text = "Exit"
- $Button.Add_Click({gtfo})
- $Form.Controls.Add($Button)
- ############################################## end buttons
- $Form.Add_Shown({$Form.Activate()})
- $form.Text = "Password Reset Tool"
- [void] $Form.ShowDialog()
Advertisement
Add Comment
Please, Sign In to add comment