Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save vMarkusK/b50bfac92082e3ecf3f805dd8602b179 to your computer and use it in GitHub Desktop.
Save vMarkusK/b50bfac92082e3ecf3f805dd8602b179 to your computer and use it in GitHub Desktop.
PowerShell Password complexity requirements
$Credential = Get-Credential
$Password = $Credential.GetNetworkCredential().Password
if(($Password -cmatch '[a-z]') -and ($Password -cmatch '[A-Z]') -and ($Password -match '\d') -and ($Password.length -ge 12) -and $Password -match '!|@|#|%|^|&|$|_') {
Remove-Variable Password
Write-Output "Password is valid"
}
else {
Remove-Variable Password
$Valid = $false
Throw "Invalid Password!
`nPassword must meet complexity requirements:`nAt least one upper case English letter [A-Z]`nAt least one lower case English letter [a-z]`nAt least one digit [0-9]`nAt least one special character (!,@,%,^,&,$,_)`nPassword length must be 12 characters or more."
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment