Menu
CoddyTech

Digits And Capitals

Part of the PowerShell Basics section of Coddy's PowerShell journey. Lesson 23 of 28.

challenge icon

Challenge

Easy

Strong passwords mix in digits and capital letters. Count both; keep everything you wrote so far.

  1. $pw.ToCharArray() gives the characters of the password as an array. Loop over it with foreach.
  2. [char]::IsDigit($c) is True for a digit and [char]::IsUpper($c) for a capital letter. Count each kind.
  3. After the length line, print Digits: and the number of digits, then Capitals: and the number of capital letters.

With the input Sunflower42, your script prints:

Password Checker
================
Password: Sunflower42
Characters: 11
Length: OK
Digits: 2
Capitals: 1

Try it yourself

# Password Checker
Write-Output "Password Checker"
Write-Output "================"
$pw = Read-Host "Password"
Write-Output "Characters: $($pw.Length)"
if ($pw.Length -ge 8) {
    Write-Output "Length: OK"
} else {
    Write-Output "Length: too short (need 8)"
}

All lessons in PowerShell Basics