Created
February 6, 2015 21:49
-
-
Save mortenya/c8e7bbfd78e65dacc059 to your computer and use it in GitHub Desktop.
A very simple Directory Searcher example.
This file contains 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
$strFilter = "(&(objectClass=Person)(objectCategory=User))" | |
$objDomain = New-Object System.DirectoryServices.DirectoryEntry | |
$objSearcher = New-Object System.DirectoryServices.DirectorySearcher | |
$objSearcher.SearchRoot = $objDomain | |
$objSearcher.PageSize = 1000 | |
$objSearcher.Filter = $strFilter | |
$objSearcher.SearchScope = "Subtree" | |
$colProplist = "name", "samAccountName" | |
foreach ($i in $colPropList){$objSearcher.PropertiesToLoad.Add($i)} | |
$colResults = $objSearcher.FindAll() | |
foreach ($objResult in $colResults) | |
{$objItem = $objResult.Properties; $objItem.name} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment