Skip navigation

Q. How can a script enumerate the printers that are listed in Active Directory?

In tip 8220 » How can I retrieve printer capability information from Active Directory, I used DSQUERY to return the following printer attributes:

printShareName
PrinterName
location
description
shortServerName
printPagesPerMinute
printMaxResolutionSupported
printOrientationsSupported
printColor
printBinNames
printDuplexSupported
printMediaReady
printStaplingSupported
printCollate
printLanguage
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:\Folder\adprinters.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 = objConnection
objCommand.CommandText = "Select printerName, serverName from " _
    & " 'LDAP://" & strDomain & "' where objectClass='printQueue'"
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Timeout") = 30
objCommand.Properties("Searchscope") = 2
objCommand.Properties("Cache Results") = False
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
    Wscript.Echo 
" & objRecordSet.Fields("serverName").Value &
,
& objRecordSet.Fields("printerName").Value &
" objRecordSet.MoveNext Loop


Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish