Steps to blocklist weak passwords using PowerShell

Step 1: Create a weak passwords list

Store weak passwords in a text file (C:\BlocklistPasswords.txt). Add more weak passwords to this list as needed.

password
123456
qwerty
admin
welcome

Step 2: Check if a user's password is in the blocklist

Compare a user’s password hash against the blocklist. This script below checks if any user is using a weak password.

$weakPasswords = Get-Content "C:\BlocklistPasswords.txt"
$users = Get-ADUser -Filter * -Properties msDS-UserPasswordExpiryTimeComputed

foreach ($user in $users) {
$password = ConvertTo-SecureString -String "userpassword" -AsPlainText -Force
if ($weakPasswords -contains $password) {
Write-Host "$($user.SamAccountName) has a weak password."
}
}

Step 3: Enforce a strong password policy

Modify the default domain password policy to enforce complexity. This sets a minimum length of 12 characters, requires complex passwords, and locks the account after five failed attempts.

Set-ADDefaultDomainPasswordPolicy -Identity "yourdomain.com" -MinPasswordLength 12 -ComplexityEnabled $true -LockoutThreshold 5

Step 4: Notify users with weak passwords

Send email alerts to users found with weak passwords. This will prompt users to update weak passwords.

foreach ($user in $users) {
if ($weakPasswords -contains $user.Password) {
Send-MailMessage -To $user.EmailAddress -From "admin@yourdomain.com" -Subject "Weak Password Alert" -Body "Please change your password immediately."
}
}

FAQs

1. How can I check if a password is weak?

Run the script below to check for users who use weak or old passwords.

Get-ADUser -Filter * -Properties PasswordLastSet | Where-Object {($_.PasswordLastSet -eq $null) -or ($_.PasswordLastSet -lt (Get-Date).AddDays(-90))}

2. How do I prevent users from using weak passwords?

Use fine-grained password policies (FGPP) and enforce complexity rules using the script below.

New-ADFineGrainedPasswordPolicy -Name "StrictPolicy" -Precedence 1 -MinPasswordLength 12 -ComplexityEnabled $true

This requires passwords to be at least 12 characters long and complex.

3. Can I check if a weak password was used recently?

Yes, check password history with the script below. This shows how many old passwords are stored in history to prevent reuse.

Get-ADUser -Identity username -Properties msDS-PasswordHistoryLength
 
  • Step 1: Create a weak passwords list
  • Step 2: Check if a user's password is in the blocklist
  • Step 3: Enforce a strong password policy
  • Step 4: Notify users with weak passwords
  • FAQs

ADSelfService Plus trusted by

A single pane of glass for complete self service password management
Email Download Link