Pages

12/16/2013

Searching Active Directory user objects for a values in an attribute

Searching Active Directory user objects for value in an attribute:
The following will look for user objects with any value in "audio" attribute
$strFilter = "(&(objectCategory=User)(audio=*))"

$objDomain = New-Object System.DirectoryServices.DirectoryEntry

$objSearcher = New-Object System.DirectoryServices.DirectorySearcher

$objSearcher.SearchRoot = $objDomain

$objSearcher.PageSize = 4000

$objSearcher.Filter = $strFilter

$objSearcher.SearchScope = "Subtree"

$colProplist = "name"

foreach ($i in $colPropList){$objSearcher.PropertiesToLoad.Add($i)}

$colResults = $objSearcher.FindAll()

foreach ($objResult in $colResults)

    {$objItem = $objResult.Properties; $objItem.name}

No comments: