Sample script that searches Active Directory for all the HP LaserJet M4345 MFP PCL 6 printers. The driverName attribute is replicated to the Global Catalog. This means you can connect to a Global Catalog server and search across the forest for all printers that use a specified print driver.
$strFilter = "(&(objectCategory=printQueue)(driverName=HP LaserJet M4345 MFP PCL 6))" $objDomain = New-Object System.DirectoryServices.DirectoryEntry $objSearcher = New-Object System.DirectoryServices.DirectorySearcher $objSearcher.SearchRoot = $objDomain $objSearcher.PageSize = 1000 $objSearcher.Filter = $strFilter $colProplist = "name" foreach ($i in $colPropList){$objSearcher.PropertiesToLoad.Add($i)} $colResults = $objSearcher.FindAll() foreach ($objResult in $colResults) {$objItem = $objResult.Properties; $objItem.name}
$strFilter = "(&(objectCategory=printQueue)(driverName=HP LaserJet M4345 MFP PCL 6))" $objDomain = New-Object System.DirectoryServices.DirectoryEntry $objSearcher = New-Object System.DirectoryServices.DirectorySearcher $objSearcher.SearchRoot = $objDomain $objSearcher.PageSize = 1000 $objSearcher.Filter = $strFilter $colProplist = "name" foreach ($i in $colPropList){$objSearcher.PropertiesToLoad.Add($i)} $colResults = $objSearcher.FindAll() foreach ($objResult in $colResults) {$objItem = $objResult.Properties; $objItem.name}