Forum Discussion
PS array performance >40K entries
- 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.
I would create a hash table where UserPrincipalName is the key and the user properties are the value.
$AllADUsers = Get-ADUser -Filter "*" -properties SAMAccountName, DisplayName, UserPrincipalName, Company, Office,Department, Manager, Description, Created, LastLogonDate, EmployeeType,Info -Server $ADServer -Credential $c
$AllADUsersHash = [ordered]@{}
$AllADUsers | ForEach-Object { $AllADUsersHash.add($_.UserPrincipalName,$_)}
$AllADUsersHash["Joe@microsoft.com"]
# or
$AllADUsersHash.Item("Joe@microsoft.com")
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.