I have an array with folder names. I want to loop thru this array and find out if an entry is only 7 in length and only contain numbers.
Can anyone please push me in the correct direction? Thanks!
One solution is while looping through the array names check if the two conditions are met like so:
foreach ($name in "test", "1234567", "test02", "001") {
if ($name.Length -eq 7 -and $name -match '^\d+$'){
Write-Host $name
}
}
$array -match '^\d{7}$'