Skip to content

Instantly share code, notes, and snippets.

@tareq2
Created November 15, 2023 20:33
Show Gist options
  • Select an option

  • Save tareq2/37ccc533065d2be573c776ae26e34142 to your computer and use it in GitHub Desktop.

Select an option

Save tareq2/37ccc533065d2be573c776ae26e34142 to your computer and use it in GitHub Desktop.
Powershell to query ldap to find user with an email or any other property
see this site for filter
https://confluence.atlassian.com/kb/how-to-write-ldap-search-filters-792496933.html
$Searcher = New-Object DirectoryServices.DirectorySearcher
$Searcher.SearchRoot = 'LDAP://test.example.local:389/OU=example Root,DC=example,DC=local'
$Searcher.Filter = '(&(email=*))'
$res = $Searcher.FindAll() | Sort-Object path
foreach ($usrTmp in $res)
{
Write-Host $usrTmp.Properties["Name"]
}
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