functions/private/Test-AADPasswordComplexity.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
Function Test-AADPasswordComplexity {
    [outputtype([string])]
    [cmdletbinding()]
    param(
        [Parameter(Mandatory=$true)]
        [ValidateNotNullOrEmpty()]
        [string]$Password,
        [Parameter()]
        [ValidateNotNullOrEmpty()]
        [int]$MinimumLength = 8
    )

    begin{
        $PasswordRegex = "(?=^.{$($MinimumLength),255}$)((?=.*\d)(?=.*[A-Z])(?=.*[a-z])|(?=.*\d)(?=.*[^A-Za-z0-9])(?=.*[a-z])|(?=.*[^A-Za-z0-9])(?=.*[A-Z])(?=.*[a-z])|(?=.*\d)(?=.*[A-Z])(?=.*[^A-Za-z0-9]))^."
    }
    process{
            if($Password -match $PasswordRegex){
                return $true
            } else {
                return $false
            }
    }
    end{}
    
}