1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
|
[void][system.Reflection.Assembly]::LoadWithPartialName('System.windows.forms')
[void][reflection.assembly]::loadwithpartialname('System.drawing')
$domaine = [ADSI]'LDAP://CN='
$domaine2 = ',ou= VOTRE OU,dc=Votre domaine,dc=Votre domaine,dc=local'
#Création du form principale
$form = New-Object Windows.Forms.Form
#Affichage d'un titre
$Form.Text = 'Reinitialisation du MDP'
#dimension du Form
$Form.size = New-Object System.Drawing.Size @(350,250)
#Création d'un bouton quitter à cliquer
$Bouton_quitter = New-Object System.Windows.Forms.Button
$Bouton_quitter.Text = 'Quitter'
#Position du bouton
$Bouton_quitter.Location = New-Object System.Drawing.Size(150,170)
#Ajustement de la taille
$Bouton_quitter.Size = New-Object System.Drawing.Size(80,30)
#Création d'un bouton reset de mdp à cliquer
$Bouton_reset = New-Object System.Windows.Forms.Button
$Bouton_reset.Text = 'Reset le MDP'
$Bouton_reset.Location = New-Object System.Drawing.Size(50,170)
$Bouton_reset.Size = New-Object System.Drawing.Size(80,30)
#Ajout d'un label
$Label_prenom = New-Object System.Windows.forms.Label
#$Label_but.AutoSize = $true
$Label_prenom.Location = New-Object System.Drawing.Point(50,20)
$Label_prenom.Name = 'Label_but'
$Label_prenom.Size = New-Object System.Drawing.Size(140,30)
$Label_prenom.Tabindex = 5
$Label_prenom.Text = 'Veuillez entrez le Prénom'
#Ajout d'un label
$Label_nom = New-Object System.Windows.forms.Label
#$Label_but.AutoSize = $true
$Label_nom.Location = New-Object System.Drawing.Point(50,100)
$Label_nom.Name = 'Label_but'
$Label_nom.Size = New-Object System.Drawing.Size(140,30)
$Label_nom.Tabindex = 5
$Label_nom.Text = 'Veuillez entrez le Nom'
#Ajout d'une textbox
$Textbox_prenom = New-Object System.Windows.Forms.Textbox
$Textbox_prenom.Location = New-Object System.Drawing.Point(70,60)
$Textbox_prenom.Multiline = $true
$Textbox_prenom.Name = 'Textbox_prenom'
$Textbox_prenom.Size = New-Object System.Drawing.Size(130, 30)
$Textbox_prenom.TabIndex = 2
#Ajout d'une textbox
$Textbox_nom = New-Object System.Windows.Forms.Textbox
$Textbox_nom.Location = New-Object System.Drawing.Point(70,130)
$Textbox_nom.Multiline = $true
$Textbox_nom.Name = 'Textbox_nom'
$Textbox_nom.Size = New-Object System.Drawing.Size(130, 30)
$Textbox_nom.TabIndex = 3
#Ajout de l'évenement 'clic gauche' au bouton_quitter
$Bouton_quitter.Add_Click(
{
$Form.close()
})
#Ajout de l'évenement 'clic gauche' au bouton_reset $domaine + $Login + $domaine2'
$Bouton_reset.Add_Click(
{
#Set up random number generator
$rand = New-Object System.Random
#Generate a new 10 character password
1..3 | ForEach { $NewPassword = $NewPassword + [char]$rand.next(33,64) }
1..3 | ForEach { $NewPassword = $NewPassword + [char]$rand.next(64,90) }
1..3 | ForEach { $NewPassword = $NewPassword + [char]$rand.next(97,122) }
1..2 | ForEach { $NewPassword = $NewPassword + [char]$rand.next(48,57) }
#write-host "le mdp est $NewPassword"
[string]$Login_prenom = $Textbox_prenom.get_text()
[string]$Login_nom = $Textbox_nom.get_text()
$Login = $Login_prenom + " " + $Login_nom
$login_complet=[ADSI] "LDAP://CN=$Login ,OU=Votre OU,DC=VOtre domaine,DC=VOtre domaine,DC=local"
$Login_complet.SetPassword("$NewPassword")
$Login_complet.pwdlastset = 0
$Login_complet.SetInfo()
$login_complet2=[ADSI] "LDAP://CN=$login,OU=Votre OU,DC=Votre domaine,DC=Votre domaine,DC=local"
$expediteur = "adresse_mail@expediteur"
$destinataire = $login_complet2.mail
$serveur = "Serveur.mail"
$objet = "CONFIDENTIEL - Réintialisation de votre MDP "
$texte = "Bonjour,`n`n Vous trouverez ci-dessous les informations relative à la réinitialisation de votre mot de passe. `n`n Votre nouveau Mot De Passe est : $NewPassword"
$message = new-object System.Net.Mail.MailMessage
$message.body = "$texte"
$message.from = $expediteur
$message.subject = $objet
$message.to.add("$destinataire")
$message.bcc.add('Une adresse mail en copie (celle de ladmin par exemple)')
$SMTPclient = new-object System.Net.Mail.SmtpClient
$SMTPclient.set_host($serveur)
$SMTPAuthUsername = "adresse_mail@expediteur ou username"
$SMTPAuthPassword = "MDP"
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential($SMTPAuthUsername, $SMTPAuthPassword)
$SMTPclient.Send($message)
$Popup_confirm = New-Object -ComObject wscript.shell
$Popupconfirm = $Popup_confirm.popup( "Le Mot de passe pour $Login à été réinitialisé. `nVoulez-vous en créer un autre?", 0 , "Réinitialisation de Mot de Passe", 1)
if ( $Popupconfirm -ne 1){
$Form.close()
}
})
#Ajout du bouton dans le Form
$Form.controls.Add($Label_prenom)
$Form.controls.Add($Label_nom)
$Form.controls.Add($Textbox_prenom)
$Form.controls.Add($Textbox_nom)
$Form.controls.Add($Bouton_reset)
$Form.controls.Add($Bouton_quitter)
$Form.Showdialog() |
Partager