Skip to content

Instantly share code, notes, and snippets.

@emiliano-poggi
Last active May 11, 2021 01:27
Show Gist options
  • Save emiliano-poggi/d49252f78c9e79a85ded to your computer and use it in GitHub Desktop.
Save emiliano-poggi/d49252f78c9e79a85ded to your computer and use it in GitHub Desktop.
How To PowerShell Active Directory Query using ADSISearcher, no ActiveDirectory module

How To PowerShell Active Directory Query using ADSISearcher

Create the new adsisearcher object:

$searcher = [adsisearcher]""

Test searcher:

$searcher.SearchRoot()

Set a filter:

$searcher.Filter = "givenname=*pippo"

Query all results:

$searcher.FindAll()

Query first result:

$result = $searcher.FindOne()

Once you have a result you can get its properties:

$result.Properties

For example, to get all groups the user is member of:

$result.Properties["MemberOf"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment