Forum Discussion
blairkei
Nov 10, 2020Tin Contributor
PS array performance >40K entries
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...
- Nov 10, 2020
Joe_Cauffiel Thanks for the alternative solution. My next step was to switch over to using a HASH array but it still does not explain why .contains is taking 2ms and .where is taking 1000ms when they are both using the same search criteria and scanning through the array. I'm wondering if I am missing an option on the ".where" somehow.
farismalaeb
Nov 10, 2020Steel Contributor
The Contain method will return true or false, but to use it in your case, I guess you will need to add
$AllADUsers.UserPrincipalName.Contains($SearchID)
I guess this is related to how many items in the object, so in your case, each object of the array contain multiple items. not a
Key= Value
if you check the Where{} statement, you are going to each item properties, and this is why you get the result.
The $AllADUsers.Contains("*user1@necad.ae*") is not equal to $AllADUsers.Where({$_.UserPrincipalName -eq "$SearchID"})
- blairkeiNov 11, 2020Tin Contributor
farismalaeb Hi
The contain statement only takes 2ms
The where statement takes 1000ms
The search string is the same in both cases. So changing the contains statement won't address my issue with the where method.