Hi
I’m trying to find the fastest way to search a large array (40K entries) for a value. However, I’m struggling with the way in which the array is working.
I read in all AD users as shown below
$AllADUsers = Get-ADUser -Filter "*" -properties SAMAccountName, DisplayName, UserPrincipalName, Company, Office,
Department, Manager,
Description, Created, LastLogonDate, EmployeeType,Info
-Server $ADServer -Credential $c
|select SAMAccountName, DisplayName, UserPrincipalName, Company, Office, Department, Manager,
Description, Created, LastLogonDate, EmployeeType,Info
If I search the array using the .Contains method it finds the entry in around 2ms
$AllADUsers.Contains($SearchID)
$AllADUsers.Where({$_.UserPrincipalName -eq "$SearchID"})
In fact it was faster to use Get-AdUser for each search using on 900ms than to pull it from the array.
I’ve also tried other variations to no avail, such as:
$AllADUsers | where-object {$_.UserPrincipalName -eq $SearchID}
Any help gratefully received.
Thanks
Keith