Public/TenantConfiguration/Baseline/Add-AuthenticationStrengths.ps1

function Add-AuthenticationStrengths {
    param(
        [Parameter(Mandatory)]
        [string]$TenantId
    )

    try {
        Connect-CustomerGraph -CustomerTenantId $TenantId

        $AuthStrengths = Get-MgPolicyAuthenticationStrengthPolicy -All

        $AuthStrengthsFiles = Get-ChildItem -Path "$PSScriptRoot\AuthenticationStrengths" -Filter *.json
        foreach($AuthStrengthsFile in $AuthStrengthsFiles) {
            $AuthStrength = Get-Content -Path $AuthStrengthsFile.FullName | ConvertFrom-Json -AsHashtable -Depth 100
            if($AuthStrengths.displayName -contains $AuthStrength.displayName) {
                Write-Host "Authentication strength '$($AuthStrength.displayName)' already exists, not creating.." -ForegroundColor Yellow
            }
            else {
                $AuthStrength = New-MgPolicyAuthenticationStrengthPolicy -BodyParameter $AuthStrength
                Write-Host "Created authentication strength '$($AuthStrength.DisplayName)'!" -ForegroundColor Green
            }
        }
    }
    catch {
        throw "Failed to create authentication strengths: $_"
    }
}