Sometimes you need to verify if a password meets some minimal requirements such as length, upper- and lowercase characters and special chars.
This simple script validates if a string / password matches at least these minimum requirements:
- At least one uppercase character
- At least one lowercase character
- At least one digit
- At least one special char
- At least 10 characters in length
1 2 3 4 5 6 7 8 9 10 11 12 13 | $password = 'mySecure!P@ssword$' $counter = 0 @('[A-Z]', '[a-z]', '\d', '[\41-\57\100\133-\140]', '.{10,}') | foreach { if(($str -creplace $_, '') -ne $str) { $counter++ } } if($counter -ge 5){ Write-Host "Strong password" } else { Write-Host "Weak password" } |