Testing a password meets complexity using PowerShell

A small bit of code to check if a password meets the Windows AD complexity rules. The only thing this does not do is check to see if the password being treated contains the username.

$pw2test = “{Enter some password to test here}”
$isGood = 0
If (-Not($pw2test -notmatch “[a-zA-Z0-9]”)) #check for special chars
     { $isGood++ }
If ($pw2test -match “[0-9]”)
     { $isGood++ }
If ($pw2test -cmatch “[a-z]”)
     { $isGood++ }
If ($pw2test -cmatch “[A-Z]”)
     { $isGood++ }
If ($isGood -ge 3)
     { $pw2test + ” is a good password” | Out-Default }
     { $pw2test + ” is not a good password” | Out-Default }


Comments are closed.