Finds all active computer account objects under a root path. This example searches the domainname.local domain root.
$Root = "LDAP://DC=domainname,DC=local" $objDomain = New-Object System.DirectoryServices.DirectoryEntry($Root) $objSearcher = New-Object System.DirectoryServices.DirectorySearcher $objSearcher.SearchRoot = $objDomain $objSearcher.PageSize = 1000 $objSearcher.Filter = "(objectCategory=Computer)" $objSearcher.SearchScope = "Subtree" $colProplist = "name", "distinguishedname" foreach ($s in $colProplist) { $objSearcher.PropertiesToLoad.Add($s) | out-null } $colResults = $objSearcher.FindAll() Write-Host "Found $($colResults.count) computer(s)" foreach ($objResult in $colResults) { $objItem = $objResult.Properties $objComputer = [ADSI]"LDAP://$($objItem.distinguishedname)" If (!$objComputer.PsBase.InvokeGet("AccountDisabled")) { Write-Host $objItem.name } }