Other Posts in this Series:
- Use ADSI to List Nested Members of an AD Group (Updated)
- Use ADSI and FromFileTime to Convert Datetime Attributes in Active Directory
- Use ADSI to Find Logon Workstations in Active Directory
- Search Active Directory using PowerShell ADSISearcher Filters
- Use PowerShell ADSI to Search Users in Active Directory
This post provides a simple example of how we can use PowerShell ADSI to search computers in Active Directory. You may wish to further optimise this by using LDAP filters.
#only computers
$objSearcher=[adsisearcher]'(&(objectCategory=computer))'
$objSearcher.PageSize = 200
#specify properties to include
$colProplist = "name"
foreach ($i in $colPropList) { $objSearcher.PropertiesToLoad.Add($i) | out-null }
$colResults = $objSearcher.FindAll()
foreach ($objResult in $colResults)
{
#computer name
$assetname = ($objResult.Properties).name
write-host $assetname
}