ADSI Searcher takes way too long
i have function tests see if email address exists anywhere in active directory using proxyaddresses attrubute each users. function works, directory size of 5000 users, query takes several minutes. in exchange environment, when setting email address, management console tests if address valid , returns in couple of seconds, there must way optimize function. ideas?
function testproxy{ param ($newemail) $global:emailclear = $true $searcher = [adsisearcher]"(&(objectcategory=person)(objectclass=user)(proxyaddresses=*))" $results = $searcher.findall() foreach ($result in $results){ $addresses = $result.properties.item("proxyaddresses") foreach ($address in $addresses){ if ($address.contains(":") -eq $true){ $email = ($address -split ":")[1] } else{ $email = $address } if ($newemail.toupper() -eq $email.toupper()){ $global:emailclear = $false } } } }
5000 not large number of users ad. however, query faster if searched users have specific email address. perhaps:
$searcher = [adsisearcher]"(&(objectcategory=person)(objectclass=user)(proxyaddresses=*$newemail))"
then recordset sent dc client smaller.
richard mueller - mvp directory services
Windows Server > Windows PowerShell
Comments
Post a Comment