We help IT Professionals succeed at work.
Get Started

Powershell: Faster comparison of 2 large strings/files?

Last Modified: 2012-05-12
I have a working script, it is just way too slow...
The script compares a large text file of SMTP addresses against addresses in Active Directory.

I have done it two ways:
1st method: do a query directly against AD for each email address.
2nd: I put all of the AD ProxyAddresses, returned in a query, into a string.
Then I compare each address from the file to those values from AD.
Below is the 2nd method, which seems to be about the same speed as using AD directly for each check.

I bet you Powershell gurus know how to speed this up???

$Domain = "DC=YOUR,DC=local" # Root context of AD domain.
$SMTPDomain = "Sample.com"  # Looking for users@Sample.com

$SMTPList = get-content "C:\Script Files\TestAddresses.txt" 

$Filter = "(proxyaddresses=*smith@$SMTPDomain*)"     #### Limited to *smith...* for testing ###
$ProxyAddresses = get-qadobject -DontUseDefaultIncludedProperties -Includedproperties proxyaddresses -SearchRoot $domain -Sizelimit 0 -SearchScope Subtree -ldapFilter $Filter | Select proxyaddresses

ForEach ($email in $SMTPList) {
  	$Found = $null
	$Found = ($ProxyAddresses | Out-String | select-string -pattern $Email)
	If ($Found -eq $null)
	 Write-Host "Didn't Find: " $Email 
	 Write-Host "Was Found: " $Email

$ListNotFound | out-file -filepath "C:\Temp\NotFound.txt"
$ListFound | out-file -filepath "C:\Temp\Found.txt"

Open in new window

Watch Question
This problem has been solved!
Unlock 1 Answer and 4 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE