Skip to content

Instantly share code, notes, and snippets.

@RootUp
Created December 28, 2023 10:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RootUp/7870e859ddade793995be314470b2538 to your computer and use it in GitHub Desktop.
Save RootUp/7870e859ddade793995be314470b2538 to your computer and use it in GitHub Desktop.
LDAP Query Domain User Enum
$ldapPath = "LDAP://DC=corp,DC=inputzero,DC=io"
$filter = "(&(objectClass=user)(objectCategory=person))"
$searcher = New-Object System.DirectoryServices.DirectorySearcher
$searcher.SearchRoot = New-Object System.DirectoryServices.DirectoryEntry($ldapPath)
$searcher.Filter = $filter
$searcher.PropertiesToLoad.Add("cn") > $null
$searcher.PropertiesToLoad.Add("samAccountName") > $null
$searcher.PropertiesToLoad.Add("mail") > $null
$results = $searcher.FindAll()
foreach ($result in $results) {
$user = $result.GetDirectoryEntry()
Write-Output "CN: $($user.cn), SAM Account Name: $($user.samAccountName), Email: $($user.mail)"
}
$searcher.Dispose()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment