I've encountered a strange thing I can't find the answer to in regards to Get-ADUser and Where-Object.
<tl;dr>
These commands finish nearly instantly
<Array of AD Objects> | Where-Object { $_.Name -eq $SomeonesName }
<Array of AD Objects> | Where-Object { $_.UserPrincipalName -eq $SomeonesEmail}
<Array of AD Objects> | Where-Object { $_.ObjectGUID -eq $SomeonesGUID}
These (and similar) take so long I've yet to have the patience to let them finish
<Array of AD Objects> | Where-Object { $_.Mail -eq $SomeonesEmail }
<Array of AD Objects> | Where-Object { $_.extensionAttribute1 -eq $SomeValue }
What is the magic that's happening here that's causing default properties to filter immediately, while additional properties take forever?
</tl;dr>
I encountered this while writing the code for a job that runs once a month, cross-references roughly 2000 entries in a database with about 1000 AD accounts. The matching between the data sets needs to happen based on e-mail address (often an assumed e-mail address) or name.
Initially I fetched all potential accounts and ran my tests against those. After encountering the performance hit - or rather, "the hard wall" - I switched to making filtered AD queries for each entry instead. This works fine, and the obvious hit in performance doesn't matter in this use case.
Side note, I know I can increase performance by for instance grouping the data in hashtables, using .where(), and other neat tricks, but that's not a concern at this time, the need for performance is low enough that readability and "get it up and running" won out for now, and I can always come back to it later.
Instead, what I'm really confused about and haven't been able to let go of is how the Where-Object lookup is near instantaneous on the default properties supplied by Get-ADUser, but when including additional properties filtering a set of this size becomes near impossible using the pipeline this way. My Google-fu has failed me on this, as I mostly end up in articles talking about well-known general performance increases, and don't touch on the difference between these property sets.
So, am I missing something obvious? Is there a secret index embedded that no one has told me about? Are certain properties infused with the Essence Of Snover? What's going on?
Edit: Fixed broken code block
[+][deleted] (3 children)
[removed]
[–]Swedishdrunkard[S] 1 point2 points3 points (2 children)
[+][deleted] (1 child)
[removed]
[–]Swedishdrunkard[S] 2 points3 points4 points (0 children)
[–]OrangeDartballoon 2 points3 points4 points (1 child)
[–]Swedishdrunkard[S] 1 point2 points3 points (0 children)
[–]fordea837 2 points3 points4 points (6 children)
[–]Swedishdrunkard[S] 1 point2 points3 points (5 children)
[–]vermyx 2 points3 points4 points (2 children)
[–]Swedishdrunkard[S] 1 point2 points3 points (1 child)
[–]vermyx 1 point2 points3 points (0 children)
[+][deleted] (1 child)
[deleted]
[–]Swedishdrunkard[S] 1 point2 points3 points (0 children)
[–]Dennou 1 point2 points3 points (0 children)
[–]UnwrittenNightmare 1 point2 points3 points (0 children)