Created
March 10, 2015 21:07
-
-
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.
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
# 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