$users = Get-LocalUser foreach($username in -split $users){ $badChar = $false foreach ($char in $username.ToCharArray()) { if($char -notmatch "[A-Za-z]"){ $badChar = $true break } } $fistChar = $username[0] $validFirstLetter = $fistChar -match "[A-Za-z]" if ($badChar -or $username.Length -ge 20 -or -not $validFirstLetter ){ Write-Host "the userName " + $username + " is invalid" } }