I am trying to search through a directory with about 100K users and keep receiving "Invalid Enumeration Context". I am trying to search for all users who machine the list of UPN contained in a text file and provide back their samAccountName.
$users=Get-Content -Path "c:\temp\OracleUsers.txt"
$list= @()
$allusers= Get-ADUser -Filter * -SearchBase "dc=domain,dc=org" -ResultPageSize 0 -Server "ServerDC01" -Properties *
Foreach ($usr in $users) {
Foreach ($auser in $allusers) {
If ($usr -eq "$auser.UniversalPrincipalName") {$list+=$auser.samAccountName}
Else {$list+="$usr not found in AD"}
}
}
$list|out-file -FilePath "c:\temp\FOundUsers.txt"
Please help with any suggestions and why I am getting this error.