Q. How can a script enumerate the printers that are listed in Active Directory?
Jerold Schulman
November 13, 2006
1 Min Read
In tip 8220 How can I retrieve printer capability information from Active Directory, I used DSQUERY to return the following printer attributes:
printShareNamePrinterNamelocationdescriptionshortServerNameprintPagesPerMinuteprintMaxResolutionSupportedprintOrientationsSupportedprintColorprintBinNamesprintDuplexSupportedprintMediaReadyprintStaplingSupportedprintCollateprintLanguage
Using standard commands, I have scripted ADPrinters.vbs to return the server name and printer name, in CSV format.
The syntax for using ADPrinters.vbs is:
cscript //nologo c:Folderadprinters.vbs.
The output is displayed on the console, but can be redirected to a file, like:
"jsi001.JSIINC.COM","HP Business Inkjet 2250 (PCL5C)""jsi001.JSIINC.COM","ZFax""JSI009.JSIINC.COM","HP Officejet 6200 series"
ADPrinters.vbs contains:
Set objRootDSE = GetObject("LDAP://rootDSE")strDomain = objRootDSE.Get("defaultNamingContext")Set objConnection = CreateObject("ADODB.Connection")Set objCommand = CreateObject("ADODB.Command")objConnection.Provider = "ADsDSOObject"objConnection.Open "Active Directory Provider"Set objCommand.ActiveConnection = objConnectionobjCommand.CommandText = "Select printerName, serverName from " _ & " 'LDAP://" & strDomain & "' where objectClass='printQueue'"objCommand.Properties("Page Size") = 1000objCommand.Properties("Timeout") = 30objCommand.Properties("Searchscope") = 2objCommand.Properties("Cache Results") = FalseSet objRecordSet = objCommand.ExecuteobjRecordSet.MoveFirstDo Until objRecordSet.EOF Wscript.Echo
" & objRecordSet.Fields("serverName").Value &
,
& objRecordSet.Fields("printerName").Value &
" objRecordSet.MoveNextLoop
About the Author
Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.
You May Also Like