Skip to content

Instantly share code, notes, and snippets.

@Windos
Created September 30, 2015 01:56
Show Gist options
  • Save Windos/225c1855922c7471d839 to your computer and use it in GitHub Desktop.
Save Windos/225c1855922c7471d839 to your computer and use it in GitHub Desktop.
It turns out there are a few different ways to search for a given SamAccountName ($user) using the Get-ADUser cmdlet. As part of a bigger project, I decided to find out which method was faster.
# Speeds are measured in milliseconds and are the average over 256 test runs
# 6.3 ms
Get-ADUser -Filter { SamAccountName -eq $user }
# 6.7 ms
Get-AdUser -LDAPFilter "(SamAccountName=$user)"
# 8.5 ms
Get-ADUser -Identity $user
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment