Avant toutes choses, vérifiez le niveau de sécurité des scripts PowerShell de votre système.
Tapez la commande suivante :

PowerShell
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.

PowerShell
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser

Code source

Copiez/collez ce code source dans un terminal PowerShell ISE (interface graphique PowerShell).

PowerShell
###################################################
###################################################
############ PASSWORD GENERATOR V1.0 ##############
###################################################
########### Powerred by : Digitalglxy #############
###################################################
###################################################


Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
Add-Type -AssemblyName Microsoft.VisualBasic

# Fonction pour générer le mot de passe
function Generate-Password {
    param (
        [int]$length,
        [bool]$useUpperCase,
        [bool]$useLowerCase,
        [bool]$useNumbers,
        [bool]$useSpecialChars
    )

    $chars = ""
    if ($useLowerCase) { $chars += "abcdefghijklmnopqrstuvwxyz" }
    if ($useUpperCase) { $chars += "ABCDEFGHIJKLMNOPQRSTUVWXYZ" }
    if ($useNumbers)   { $chars += "0123456789" }
    if ($useSpecialChars) { $chars += "!@#$%^&*()_+-=[]{}|;:,.<>?/" }

    if ($chars -eq "") {
        return "Erreur : Aucun type de caractère sélectionné."
    }

    $password = ""
    for ($i = 0; $i -lt $length; $i++) {
        $randomIndex = Get-Random -Minimum 0 -Maximum $chars.Length
        $password += $chars[$randomIndex]
    }

    return $password
}

# Création de la fenêtre principale
$form = New-Object System.Windows.Forms.Form
$form.Text = "Générateur de Mot de Passe"
$form.Size = New-Object System.Drawing.Size(450, 400)
$form.StartPosition = "CenterScreen"
$form.FormBorderStyle = [System.Windows.Forms.FormBorderStyle]::FixedDialog
$form.MaximizeBox = $false
$form.BackColor = [System.Drawing.Color]::White
$form.Font = New-Object System.Drawing.Font("Segoe UI", 9, [System.Drawing.FontStyle]::Regular)

# Style Windows 11 : Couleurs et polices
$accentColor = [System.Drawing.Color]::FromArgb(0, 120, 212)
$textColor = [System.Drawing.Color]::FromArgb(32, 32, 32)
$borderColor = [System.Drawing.Color]::FromArgb(200, 200, 200)

# Titre de l'application
$labelTitle = New-Object System.Windows.Forms.Label
$labelTitle.Location = New-Object System.Drawing.Point(20, 20)
$labelTitle.Size = New-Object System.Drawing.Size(400, 30)
$labelTitle.Text = "Générateur de Mot de Passe"
$labelTitle.Font = New-Object System.Drawing.Font("Segoe UI", 14, [System.Drawing.FontStyle]::Bold)
$labelTitle.ForeColor = $textColor
$form.Controls.Add($labelTitle)

# Label pour la longueur
$labelLength = New-Object System.Windows.Forms.Label
$labelLength.Location = New-Object System.Drawing.Point(30, 70)
$labelLength.Size = New-Object System.Drawing.Size(200, 20)
$labelLength.Text = "Longueur du mot de passe :"
$labelLength.Font = New-Object System.Drawing.Font("Segoe UI", 9, [System.Drawing.FontStyle]::Regular)
$labelLength.ForeColor = $textColor
$form.Controls.Add($labelLength)

# ComboBox pour choisir la longueur (style Windows 11)
$comboLength = New-Object System.Windows.Forms.ComboBox
$comboLength.Location = New-Object System.Drawing.Point(30, 100)
$comboLength.Size = New-Object System.Drawing.Size(120, 30)
$comboLength.DropDownStyle = [System.Windows.Forms.ComboBoxStyle]::DropDownList
$comboLength.Items.AddRange(@("8", "12", "16", "22"))
$comboLength.SelectedIndex = 1
$comboLength.FlatStyle = [System.Windows.Forms.FlatStyle]::Flat
$comboLength.BackColor = [System.Drawing.Color]::White
$comboLength.ForeColor = $textColor
$comboLength.Font = New-Object System.Drawing.Font("Segoe UI", 9, [System.Drawing.FontStyle]::Regular)
$form.Controls.Add($comboLength)

# CheckBox pour les majuscules (style Windows 11)
$checkUpper = New-Object System.Windows.Forms.CheckBox
$checkUpper.Location = New-Object System.Drawing.Point(30, 150)
$checkUpper.Size = New-Object System.Drawing.Size(150, 20)
$checkUpper.Text = "Majuscules (A-Z)"
$checkUpper.Checked = $true
$checkUpper.ForeColor = $textColor
$checkUpper.Font = New-Object System.Drawing.Font("Segoe UI", 9, [System.Drawing.FontStyle]::Regular)
$form.Controls.Add($checkUpper)

# CheckBox pour les minuscules
$checkLower = New-Object System.Windows.Forms.CheckBox
$checkLower.Location = New-Object System.Drawing.Point(30, 180)
$checkLower.Size = New-Object System.Drawing.Size(150, 20)
$checkLower.Text = "Minuscules (a-z)"
$checkLower.Checked = $true
$checkLower.ForeColor = $textColor
$checkLower.Font = New-Object System.Drawing.Font("Segoe UI", 9, [System.Drawing.FontStyle]::Regular)
$form.Controls.Add($checkLower)

# CheckBox pour les chiffres
$checkNumbers = New-Object System.Windows.Forms.CheckBox
$checkNumbers.Location = New-Object System.Drawing.Point(30, 210)
$checkNumbers.Size = New-Object System.Drawing.Size(150, 20)
$checkNumbers.Text = "Chiffres (0-9)"
$checkNumbers.Checked = $true
$checkNumbers.ForeColor = $textColor
$checkNumbers.Font = New-Object System.Drawing.Font("Segoe UI", 9, [System.Drawing.FontStyle]::Regular)
$form.Controls.Add($checkNumbers)

# CheckBox pour les caractères spéciaux
$checkSpecial = New-Object System.Windows.Forms.CheckBox
$checkSpecial.Location = New-Object System.Drawing.Point(30, 240)
$checkSpecial.Size = New-Object System.Drawing.Size(200, 20)
$checkSpecial.Text = "Caractères spéciaux (!@#...)"
$checkSpecial.Checked = $true
$checkSpecial.ForeColor = $textColor
$checkSpecial.Font = New-Object System.Drawing.Font("Segoe UI", 9, [System.Drawing.FontStyle]::Regular)
$form.Controls.Add($checkSpecial)

# Bouton "Générer" (style Windows 11)
$buttonGenerate = New-Object System.Windows.Forms.Button
$buttonGenerate.Location = New-Object System.Drawing.Point(30, 280)
$buttonGenerate.Size = New-Object System.Drawing.Size(120, 35)
$buttonGenerate.Text = "Générer"
$buttonGenerate.BackColor = $accentColor
$buttonGenerate.ForeColor = [System.Drawing.Color]::White
$buttonGenerate.FlatStyle = [System.Windows.Forms.FlatStyle]::Flat
$buttonGenerate.Font = New-Object System.Drawing.Font("Segoe UI", 9, [System.Drawing.FontStyle]::Bold)
$buttonGenerate.Add_Click({
    $length = [int]$comboLength.SelectedItem
    $password = Generate-Password -length $length `
                                   -useUpperCase $checkUpper.Checked `
                                   -useLowerCase $checkLower.Checked `
                                   -useNumbers $checkNumbers.Checked `
                                   -useSpecialChars $checkSpecial.Checked
    $textPassword.Text = $password
})
$form.Controls.Add($buttonGenerate)

# Zone de texte pour afficher le mot de passe (style Windows 11)
$textPassword = New-Object System.Windows.Forms.TextBox
$textPassword.Location = New-Object System.Drawing.Point(30, 330)
$textPassword.Size = New-Object System.Drawing.Size(380, 30)
$textPassword.ReadOnly = $true
$textPassword.Font = New-Object System.Drawing.Font("Segoe UI", 10, [System.Drawing.FontStyle]::Regular)
$textPassword.BorderStyle = [System.Windows.Forms.BorderStyle]::FixedSingle
$textPassword.BackColor = [System.Drawing.Color]::White
$textPassword.ForeColor = $textColor
$form.Controls.Add($textPassword)

# Afficher la fenêtre
[System.Windows.Forms.Application]::EnableVisualStyles()
$form.ShowDialog()