Created
December 28, 2023 10:41
-
-
Save RootUp/7870e859ddade793995be314470b2538 to your computer and use it in GitHub Desktop.
LDAP Query Domain User Enum
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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