Saturday, October 16, 2010

PowerShell ADSISEARCHER Basics

The ActiveDirectory class of the Net classes has a ‘type accelerator’ in PowerShell; [adsisearcher]. This is shorthand for [System.DirectoryServices.DirectorySearcher]

We can create an instance of this object like this:


This can then be used exactly as if we used the full class name:


Which is the same as:

$searcher=New-Object System.DirectoryServices.DirectorySearcher(””)

Here are some of the easy ways we can use this object:

#find all objects with a name that starts with ‘d’,

#find an accoun with samAcountName that starts with ‘d’

#find all objects of class ‘user’

#find all groups

Note the use of wildcards.

These are just some of the simple uses for this object. We can filter on an property name, class and category. With LDAP filter syntax we can AND, OR, NOT any amount of complexity into our query.