# Get-HighestEA-Laptop.ps1 $SearchBases = @( "OU=Windows11,OU=Workstations,DC=eanet,DC=local", "OU=W8,OU=Laptop,OU=Workstations,DC=eanet,DC=local", "OU=EntraTestComputers,OU=Windows11,OU=Workstations,DC=eanet,DC=local" ) $regex = '^EA(\d+)L$' $maxNum = -1 $maxName = $null $totalMatched = 0 # RootDSE check try { $null = [ADSI]"LDAP://RootDSE" } catch { Write-Host "FAILED: Cannot bind to LDAP RootDSE" Write-Host "Reason: $($_.Exception.Message)" exit 1 } foreach ($base in $SearchBases) { Write-Host "Searching: $base" $entry = New-Object System.DirectoryServices.DirectoryEntry("LDAP://$base") $searcher = New-Object System.DirectoryServices.DirectorySearcher($entry) $searcher.PageSize = 1000 $searcher.Filter = "(&(objectCategory=computer)(name=EA*L))" $null = $searcher.PropertiesToLoad.Add("name") foreach ($r in $searcher.FindAll()) { $name = [string]$r.Properties["name"][0] if ($name -match $regex) { $totalMatched++ $num = [int]$Matches[1] if ($num -gt $maxNum) { $maxNum = $num; $maxName = $name } } } } Write-Host "" Write-Host "Matched EA####L: $totalMatched" if ($maxNum -lt 0) { Write-Host "No EA####L found in those OUs." } else { Write-Host "Highest EA####L: $maxName (Number: $maxNum)" }