Skip to content

Instantly share code, notes, and snippets.

@Erreinion
Created March 10, 2015 21:07
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Erreinion/76660c012ad05ab90182 to your computer and use it in GitHub Desktop.
Save Erreinion/76660c012ad05ab90182 to your computer and use it in GitHub Desktop.
Powershell script to query LDAP (AD) for users. Accomplished without the ActiveDirectory plug-in from Quest.
# LDAP Query
# Look for all people. Excludes the DISABLED OU
$Searcher = New-Object DirectoryServices.DirectorySearcher
$Searcher.SearchRoot = 'LDAP://CN=Users,DC=example,DC=com'
$Searcher.Filter = '(&(objectCategory=person))'
$res = $Searcher.FindAll() | Sort-Object path
foreach ($usrTmp in $res)
{
Write-Host $usrTmp.Properties["cn"]
}
Write-Host "------------------------------"
Write-Host "Number of Users Returned: " @($res).count
Write-Host
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment