Already have one in my bag'o'tricks. You can pretty safely get rid of the French stuff, I work in Canada. Sterilized code follows:
# Script to reset logged in users password w/GUI
# This script does not accept params
# Author: Fanta5tick
# Last Modified: August 30, 2016
# Variables
$i = 0
$Script:boolLang = $true
# Adds assemblies
Add-Type -AssemblyName PresentationFramework
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
# Loads GUI objForms
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.objForms")
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
# Creates objForm object
$objForm = New-Object System.Windows.Forms.Form
$objForm.Text = "Password Reset Tool"
$objForm.Size = New-Object System.Drawing.Size(330,300)
$objForm.StartPosition = "CenterScreen"
$objForm.KeyPreview = $true
$objForm.Add_KeyDown({
If ($_.KeyCode -eq "Enter") {
& $ResetPW
}
})
$objForm.Add_KeyDown({
If ($_.KeyCode -eq "Escape") {
$objForm.Close()
}
})
$objForm.MaximumSize = $objForm.Size
$objForm.MinimumSize = $objForm.Size
# Rules Label - pulled workplace rules, you'll have to enter your own
$objRulesLabel = New-Object System.Windows.Forms.Label
$objRulesLabel.Location = New-Object System.Drawing.Size(5,50)
$objRulesLabel.Size = New-Object System.Drawing.Size(300,60)
$objRulesLabel.Text = "New passwords must follow the following rules:"
$objForm.Controls.Add($objRulesLabel)
# Label for old Password
$objLabelOld = New-Object System.Windows.Forms.Label
$objLabelOld.Location = New-Object System.Drawing.Size(5,120)
$objLabelOld.Size = New-Object System.Drawing.Size(100,40)
$objLabelOld.Text = "Old Password:"
$objForm.Controls.Add($objLabelOld)
# Label for new Password
$objLabelNew = New-Object System.Windows.Forms.Label
$objLabelNew.Location = New-Object System.Drawing.Size(5,160)
$objLabelNew.Size = New-Object System.Drawing.Size(100,40)
$objLabelNew.Text = "New Password:"
$objForm.Controls.Add($objLabelNew)
# Label for confirm Password
$objLabelConf = New-Object System.Windows.Forms.Label
$objLabelConf.Location = New-Object System.Drawing.Size(5,200)
$objLabelConf.Size = New-Object System.Drawing.Size(100,40)
$objLabelConf.Text = "Confirm Password:"
$objForm.Controls.Add($objLabelConf)
# Result Label
$objResult = New-Object System.Windows.Forms.Label
$objResult.Location = New-Object System.Drawing.Size(5,240)
$objResult.Size = New-Object System.Drawing.Size(200,30)
$objResult.Forecolor = "Green"
$objResult.Text = "Ready"
$objForm.Controls.Add($objResult)
# English button
$objEngButton = New-Object System.Windows.Forms.Button
$objEngButton.Location = New-Object System.Drawing.Size(5,5)
$objEngButton.Size = New-Object System.Drawing.Size(100,30)
$objEngButton.Text = "English"
$objEngButton.Enabled = $false
$objEngButton.Add_Click({
$objRulesLabel.Text = "New passwords must follow the following rules:"
$objLabelOld.Text = "Old Password:"
$objLabelNew.Text = "New Password:"
$objLabelConf.Text = "Confirm Password:"
$objResult.Text = "Ready"
$Script:boolLang = $true
$objEngButton.Enabled = $false
$objFreButton.Enabled = $true
})
$objForm.Controls.Add($objEngButton)
# French button
$objFreButton = New-Object System.Windows.Forms.Button
$objFreButton.Location = New-Object System.Drawing.Size(110,5)
$objFreButton.Size = New-Object System.Drawing.Size(100,30)
$objFreButton.Text = "Français"
$objFreButton.Add_Click({
$objRulesLabel.Text = "Les nouveaux mots de passe doivent respecter les règles suivantes:"
$objLabelOld.Text = "Ancien Mot de Passe:"
$objLabelNew.Text = "Nouveau Mot de Passe:"
$objLabelConf.Text = "Confirmez le Mot de Passe:"
$objResult.Text = "Green"
$objResult.Text = "Prêt"
$Script:boolLang = $false
$objFreButton.Enabled = $false
$objEngButton.Enabled = $true
})
$objForm.Controls.Add($objFreButton)
# OK button
$objOKButton = New-Object System.Windows.Forms.Button
$objOKButton.Location = New-Object System.Drawing.Size(210,230)
$objOKButton.Size = New-Object System.Drawing.Size(100,30)
$objOKButton.Text = "OK"
$objOKButton.Add_Click($ResetPW)
$objForm.Controls.Add($objOKButton)
# Text box for old Password
$objTextBoxOld = New-Object System.Windows.Forms.TextBox
$objTextBoxOld.Location = New-Object System.Drawing.Size(110,120)
$objTextBoxOld.Size = New-Object System.Drawing.Size(120,120)
$objTextBoxOld.PasswordChar = '*'
$objForm.Controls.Add($objTextBoxOld)
# Text box for new Password
$objTextBoxNew = New-Object System.Windows.Forms.TextBox
$objTextBoxNew.Location = New-Object System.Drawing.Size(110,160)
$objTextBoxNew.Size = New-Object System.Drawing.Size(120,120)
$objTextBoxNew.PasswordChar = '*'
$objTextBoxNew.Add_TextChanged({
If ($objTextBoxNew.Text -cmatch '^[a-z]*$') {
$objResult.Forecolor = "Red"
If ($Script:boolLang -eq $false) {
$objResult.Text = "Besoins au moins 1 lettre majuscule"
}
Else {
$objResult.Text = "Needs at least 1 capital letter"
}
Else {
$objResult.Forecolor = "Green"
If ($Script:boolLang -eq $false) {
$objResult.Text = "Mot de passe répond aux exigences"
}
Else {
$objResult.Text = "Password meets requirements"
}
}
})
$objForm.Controls.Add($objTextBoxNew)
# Text box to confirm new Password
$objTextBoxConf = New-Object System.Windows.Forms.TextBox
$objTextBoxConf.Location = New-Object System.Drawing.Size(110,200)
$objTextBoxConf.Size = New-Object System.Drawing.Size(120,120)
$objTextBoxConf.PasswordChar = '*'
$objTextBoxConf.Add_TextChanged({
If ($objTextBoxConf.Text -notmatch $objTextBoxNew.Text){
$objResult.Forecolor = "Red"
If ($Script:boolLang -eq $false) {
$objResult.Text = "Les nouveaux mots de passe et Confirmer doivent correspondre"
}
Else {
$objResult.Text = "New and Confirm passwords must match"
}
}
Else {
$objResult.Forecolor = "Green"
If ($Script:boolLang -eq $false) {
$objResult.Text = "Prêt à changer le mot de passe"
}
$objResult.Text = "Ready to change password"
}
})
$objForm.Controls.Add($objTextBoxConf )
# OK button
$objOKButton = New-Object System.Windows.Forms.Button
$objOKButton.Location = New-Object System.Drawing.Size(210,230)
$objOKButton.Size = New-Object System.Drawing.Size(100,30)
$objOKButton.Text = "OK"
$objOKButton.Add_Click($ResetPW)
$objForm.Controls.Add($objOKButton)
# Function to reset the password
$ResetPW = {
# Sets variables
$ADSystemInfo = New-Object -ComObject ADSystemInfo
$type = $ADSystemInfo.GetType()
$user = [ADSI]"LDAP://$($type.InvokeMember('UserName', 'GetProperty', $null, $ADSystemInfo, $null))"
Try {
$user.ChangePassword($strOldPW, $strnewPW)
}
Catch {
$objResult.Forecolor = "Red"
If ($Script:boolLang -eq $false) {
$objResult.Text = "Ancien mot de passe incorrect"
}
Else {
$objResult.Text = "Old password incorrect"
}
$i = $i + 1
}
If ($i -ge 10) {
$objResult.Forecolor = "Red"
If ($Script:boolLang -eq $false) {
$objResult.Text = "S'il vous plaît appelez Helpdesk"
}
Else {
$objResult.Text = "Please call Helpdesk"
}
}
If ($Error -eq 0) {
$objResult.Forecolor = "Green"
If ($Script:boolLang -eq $false) {
$objResult.Text = "Le mot de passe a été changé"
}
Else {
$objResult.Text = "Password changed successfully"
}
}
}
# Show objForms
$objForm.Topmost = $true
$objForm.Add_Shown({$objForm.Activate()})
[void] $objForm.ShowDialog()