Friday, 20 May 2016

Powershell: Get-ADuser filtering

I have recently been asked to extract some data from Active Directory for reporting purposes.

When I was working with much smaller AD directories so a command like Get-ADuser -filter * | where {$_.enabled -eq $true} didn't take long to complete. However, while I was waiting for a similar command to complete recently, I did some reading around best practices - the one of interest being filter from the left.

I gave it a try and compared the results.

The "where" command took 2.5 mins to complete. When I ran the same thing, using the filter, to get the same results, it took just 8 seconds!

Another thing I found was that filtering using wildcards on the DistinguishedName attribute doesn't work - if this is a requirement, you still have to use the "where" to filter.

No comments:

Post a Comment