11-15-2008
Downloads: 688
File size: 306 B
Views: 3,162
Embed
 |
Find a user in your AD |
- function Get-User ($UserName)
- {
- $searcher = new-object DirectoryServices.DirectorySearcher([ADSI]"")
- $searcher.filter = "(&(objectClass=user)(sAMAccountName= $UserName))"
- $Searcher.CacheResults = $true
- $Searcher.SearchScope = �Subtree�
- $Searcher.PageSize = 1000
- $searcher.findall()
- }
simple script defines a function called Get-User which accepts a username or part of it with wildcards. It returns all users that fit your query. This code does not rely on 3rd party stuff. You can easily expand it to query for anything. Simply replace the filter expression with the filter you want. HINT: use the Microsoft MMC Active Directories Computer and Users, then create a custom query. Once done, you will see a query string. You can copy and paste that query string into this script to get the search results you need.