Created
January 15, 2019 13:20
-
-
Save vMarkusK/b50bfac92082e3ecf3f805dd8602b179 to your computer and use it in GitHub Desktop.
PowerShell Password complexity requirements
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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