Avant toutes choses, vérifiez le niveau de sécurité des scripts PowerShell de votre système.
Tapez la commande suivante :
"Get-ExecutionPolicy"
Si la commande de sortie est sur « Restricted » alors vous devez modifier le niveau de sécurité du compte en tapant la commande suivante (il faudra également valider en tapant « O » ou « Y » en fonction de la langue de votre système.
"Set-ExecutionPolicy RemoteSigned -Scope CurrentUser"
Code source
"###################################################\n###################################################\n############ PASSWORD GENERATOR V1.0 ##############\n###################################################\n########### Powerred by : Digitalglxy #############\n###################################################\n###################################################\n\n\nAdd-Type -AssemblyName System.Windows.Forms\nAdd-Type -AssemblyName System.Drawing\nAdd-Type -AssemblyName Microsoft.VisualBasic\n\n# Fonction pour g\u00e9n\u00e9rer le mot de passe\nfunction Generate-Password {\n param (\n [int]$length,\n [bool]$useUpperCase,\n [bool]$useLowerCase,\n [bool]$useNumbers,\n [bool]$useSpecialChars\n )\n\n $chars = \"\"\n if ($useLowerCase) { $chars += \"abcdefghijklmnopqrstuvwxyz\" }\n if ($useUpperCase) { $chars += \"ABCDEFGHIJKLMNOPQRSTUVWXYZ\" }\n if ($useNumbers) { $chars += \"0123456789\" }\n if ($useSpecialChars) { $chars += \"!@#$%^&*()_+-=[]{}|;:,.<>?\/\" }\n\n if ($chars -eq \"\") {\n return \"Erreur : Aucun type de caract\u00e8re s\u00e9lectionn\u00e9.\"\n }\n\n $password = \"\"\n for ($i = 0; $i -lt $length; $i++) {\n $randomIndex = Get-Random -Minimum 0 -Maximum $chars.Length\n $password += $chars[$randomIndex]\n }\n\n return $password\n}\n\n# Cr\u00e9ation de la fen\u00eatre principale\n$form = New-Object System.Windows.Forms.Form\n$form.Text = \"G\u00e9n\u00e9rateur de Mot de Passe\"\n$form.Size = New-Object System.Drawing.Size(450, 400)\n$form.StartPosition = \"CenterScreen\"\n$form.FormBorderStyle = [System.Windows.Forms.FormBorderStyle]::FixedDialog\n$form.MaximizeBox = $false\n$form.BackColor = [System.Drawing.Color]::White\n$form.Font = New-Object System.Drawing.Font(\"Segoe UI\", 9, [System.Drawing.FontStyle]::Regular)\n\n# Style Windows 11 : Couleurs et polices\n$accentColor = [System.Drawing.Color]::FromArgb(0, 120, 212)\n$textColor = [System.Drawing.Color]::FromArgb(32, 32, 32)\n$borderColor = [System.Drawing.Color]::FromArgb(200, 200, 200)\n\n# Titre de l'application\n$labelTitle = New-Object System.Windows.Forms.Label\n$labelTitle.Location = New-Object System.Drawing.Point(20, 20)\n$labelTitle.Size = New-Object System.Drawing.Size(400, 30)\n$labelTitle.Text = \"G\u00e9n\u00e9rateur de Mot de Passe\"\n$labelTitle.Font = New-Object System.Drawing.Font(\"Segoe UI\", 14, [System.Drawing.FontStyle]::Bold)\n$labelTitle.ForeColor = $textColor\n$form.Controls.Add($labelTitle)\n\n# Label pour la longueur\n$labelLength = New-Object System.Windows.Forms.Label\n$labelLength.Location = New-Object System.Drawing.Point(30, 70)\n$labelLength.Size = New-Object System.Drawing.Size(200, 20)\n$labelLength.Text = \"Longueur du mot de passe :\"\n$labelLength.Font = New-Object System.Drawing.Font(\"Segoe UI\", 9, [System.Drawing.FontStyle]::Regular)\n$labelLength.ForeColor = $textColor\n$form.Controls.Add($labelLength)\n\n# ComboBox pour choisir la longueur (style Windows 11)\n$comboLength = New-Object System.Windows.Forms.ComboBox\n$comboLength.Location = New-Object System.Drawing.Point(30, 100)\n$comboLength.Size = New-Object System.Drawing.Size(120, 30)\n$comboLength.DropDownStyle = [System.Windows.Forms.ComboBoxStyle]::DropDownList\n$comboLength.Items.AddRange(@(\"8\", \"12\", \"16\", \"22\"))\n$comboLength.SelectedIndex = 1\n$comboLength.FlatStyle = [System.Windows.Forms.FlatStyle]::Flat\n$comboLength.BackColor = [System.Drawing.Color]::White\n$comboLength.ForeColor = $textColor\n$comboLength.Font = New-Object System.Drawing.Font(\"Segoe UI\", 9, [System.Drawing.FontStyle]::Regular)\n$form.Controls.Add($comboLength)\n\n# CheckBox pour les majuscules (style Windows 11)\n$checkUpper = New-Object System.Windows.Forms.CheckBox\n$checkUpper.Location = New-Object System.Drawing.Point(30, 150)\n$checkUpper.Size = New-Object System.Drawing.Size(150, 20)\n$checkUpper.Text = \"Majuscules (A-Z)\"\n$checkUpper.Checked = $true\n$checkUpper.ForeColor = $textColor\n$checkUpper.Font = New-Object System.Drawing.Font(\"Segoe UI\", 9, [System.Drawing.FontStyle]::Regular)\n$form.Controls.Add($checkUpper)\n\n# CheckBox pour les minuscules\n$checkLower = New-Object System.Windows.Forms.CheckBox\n$checkLower.Location = New-Object System.Drawing.Point(30, 180)\n$checkLower.Size = New-Object System.Drawing.Size(150, 20)\n$checkLower.Text = \"Minuscules (a-z)\"\n$checkLower.Checked = $true\n$checkLower.ForeColor = $textColor\n$checkLower.Font = New-Object System.Drawing.Font(\"Segoe UI\", 9, [System.Drawing.FontStyle]::Regular)\n$form.Controls.Add($checkLower)\n\n# CheckBox pour les chiffres\n$checkNumbers = New-Object System.Windows.Forms.CheckBox\n$checkNumbers.Location = New-Object System.Drawing.Point(30, 210)\n$checkNumbers.Size = New-Object System.Drawing.Size(150, 20)\n$checkNumbers.Text = \"Chiffres (0-9)\"\n$checkNumbers.Checked = $true\n$checkNumbers.ForeColor = $textColor\n$checkNumbers.Font = New-Object System.Drawing.Font(\"Segoe UI\", 9, [System.Drawing.FontStyle]::Regular)\n$form.Controls.Add($checkNumbers)\n\n# CheckBox pour les caract\u00e8res sp\u00e9ciaux\n$checkSpecial = New-Object System.Windows.Forms.CheckBox\n$checkSpecial.Location = New-Object System.Drawing.Point(30, 240)\n$checkSpecial.Size = New-Object System.Drawing.Size(200, 20)\n$checkSpecial.Text = \"Caract\u00e8res sp\u00e9ciaux (!@#...)\"\n$checkSpecial.Checked = $true\n$checkSpecial.ForeColor = $textColor\n$checkSpecial.Font = New-Object System.Drawing.Font(\"Segoe UI\", 9, [System.Drawing.FontStyle]::Regular)\n$form.Controls.Add($checkSpecial)\n\n# Bouton \"G\u00e9n\u00e9rer\" (style Windows 11)\n$buttonGenerate = New-Object System.Windows.Forms.Button\n$buttonGenerate.Location = New-Object System.Drawing.Point(30, 280)\n$buttonGenerate.Size = New-Object System.Drawing.Size(120, 35)\n$buttonGenerate.Text = \"G\u00e9n\u00e9rer\"\n$buttonGenerate.BackColor = $accentColor\n$buttonGenerate.ForeColor = [System.Drawing.Color]::White\n$buttonGenerate.FlatStyle = [System.Windows.Forms.FlatStyle]::Flat\n$buttonGenerate.Font = New-Object System.Drawing.Font(\"Segoe UI\", 9, [System.Drawing.FontStyle]::Bold)\n$buttonGenerate.Add_Click({\n $length = [int]$comboLength.SelectedItem\n $password = Generate-Password -length $length `\n -useUpperCase $checkUpper.Checked `\n -useLowerCase $checkLower.Checked `\n -useNumbers $checkNumbers.Checked `\n -useSpecialChars $checkSpecial.Checked\n $textPassword.Text = $password\n})\n$form.Controls.Add($buttonGenerate)\n\n# Zone de texte pour afficher le mot de passe (style Windows 11)\n$textPassword = New-Object System.Windows.Forms.TextBox\n$textPassword.Location = New-Object System.Drawing.Point(30, 330)\n$textPassword.Size = New-Object System.Drawing.Size(380, 30)\n$textPassword.ReadOnly = $true\n$textPassword.Font = New-Object System.Drawing.Font(\"Segoe UI\", 10, [System.Drawing.FontStyle]::Regular)\n$textPassword.BorderStyle = [System.Windows.Forms.BorderStyle]::FixedSingle\n$textPassword.BackColor = [System.Drawing.Color]::White\n$textPassword.ForeColor = $textColor\n$form.Controls.Add($textPassword)\n\n# Afficher la fen\u00eatre\n[System.Windows.Forms.Application]::EnableVisualStyles()\n$form.ShowDialog()\n"