Created
November 15, 2023 20:33
-
-
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
This file contains hidden or 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
| 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