?
Solved

Enumerating Clustered Print Server Printers with WMI and VBS?

Posted on 2008-06-26
9
Medium Priority
?
3,438 Views
Last Modified: 2012-06-27
Hello Experts,

I'm trying to figure out how to enumerate Printers from Clustered Print Server using WMI and VB Script but I can't get any results back.

If I use the same script on NON Clustered Print Server I have no problems and can use SELECT statement to get any information supported by Win32_Printer class, but the same thing doesn't seem to work for Clustered Print Server?
I have attached the VBS code below that works on NON Clustered Print Server but Can't get anything from Clustered Print Server

I also know that there is a way to Enumerate all AD Published Printers but I was not able to use LIKE operator in the SELECT Statement with ADOOB connection script...I have attached that script as well on the Bottom so please if anyone has any suggestions I would greatly appreciate it.

Thanks!
'VBS CODE for enumerating SINGLE Print Server
 
'On Error Resume next
strComputer = "NYPRINT"
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters =  objWMIService.ExecQuery _
    ("SELECT * FROM Win32_Printer WHERE PortName LIKE '%10.%'")
 
 
 
 
For Each objPrinter in colInstalledPrinters
'    Wscript.Echo "Port Name: " & objPrinter.PortName
'    Wscript.Echo "Collate: " & objPrinter.Collate
	WScript.Echo "Printer Name: " & objPrinter.Name & vbCrLf & vbCrLf &_
    "Port: " & objPrinter.PortName
'    Wscript.Echo "Driver Version: " & objPrinter.DriverVersion
'    Wscript.Echo "Description: " & objPrinter.Description
'    Wscript.Echo "Horizontal Resolution: " & _
'        objPrinter.HorizontalResolution
'    If objPrinter.Orientation = 1 Then
'        strOrientation =  "Portrait"
'    Else 
'        strOrientation = "Landscape"
'    End If
'    Wscript.Echo "Orientation : " & strOrientation
'    Wscript.Echo "Paper Length: " & objPrinter.PaperLength / 254
'    Wscript.Echo "Paper Width: " & objPrinter.PaperWidth / 254
'    Wscript.Echo "Print Quality: " & objPrinter.PrintQuality
'    Wscript.Echo "Scale: " & objPrinter.Scale
'    Wscript.Echo "Specification Version: " & _
'        objPrinter.SpecificationVersion
'    If objPrinter.TTOption = 1 Then
'        strTTOption = "Print TrueType fonts as graphics."
'    ElseIf objPrinter.TTOption = 2 Then
'        strTTOption = "Download TrueType fonts as soft fonts."
'    Else
'        strTTOption = "Substitute device fonts for TrueType fonts."
'    End If
'    Wscript.Echo "True Type Option: " & strTTOption
'    Wscript.Echo "Vertical Resolution: " & objPrinter.VerticalResolution
Next
 
'=============================================================
'2ND Script for Enumerating all AD Published Printers
Const ADS_SCOPE_SUBTREE = 2
 
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://DC=fabrikam,DC=com'  where objectClass='printQueue'"  
 
'Problem in this statement is that I can't use LIKE operator to search 'for specific printers like "Select printerName from '"'LDAP://DC=YourDomain,DC=com' were printerName LIKE '%color'" for 'example
 
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE 
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
 
Do Until objRecordSet.EOF
    Wscript.Echo "Printer Name: " & objRecordSet.Fields("printerName").Value
    Wscript.Echo "Server Name: " & objRecordSet.Fields("serverName").Value
    objRecordSet.MoveNext
Loop

Open in new window

0
Comment
Question by:Hubasan
  • 3
  • 3
6 Comments
 
LVL 17

Expert Comment

by:Jared Luker
ID: 21876899
Are you pointing at the virtual server name?  Are you pointing to the server that is currently in charge of the cluster and has all groups online?  Are you pointing to the secondary server that has all the groups offline?
0
 
LVL 7

Author Comment

by:Hubasan
ID: 21876948
Yeah I have tried to point to Virtual Server name (NYPRINT) and to the print server that is currently in charge of the cluster (NY030) but got the same problem were no results are returned.
0
 
LVL 17

Expert Comment

by:Jared Luker
ID: 21876973
Is there any firewalls or special port blocking on those clustered machines that might be blocking WMI?
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 7

Author Comment

by:Hubasan
ID: 21877034
No port blocking since I already used WMI to enumerate hardware of this machine and it works as excpected. It seems to be a problem only with enumerating printers using Win32_Printers class.
0
 
LVL 7

Accepted Solution

by:
Hubasan earned 0 total points
ID: 21975709
Well since no-one was really able to help me here, I have used a different approach to this problem with a script that goes to Active Directory using ADODB connection and just enumerates published printers and then using an objectClass of  "printQueue" and filtering it with printColor=True gets a list of published Color printers that I needed.

It took me some time to find out that "portName" attribute of printQueue object is an actual array and not a string, since our beloved Technet article never mentions that, but I made it at the end.

For all of you interested about this article and printQueue object here is the link:
http://www.microsoft.com/technet/scriptcenter/guide/sas_prn_vypc.mspx?mfr=true


Below I have attached a script that can read all Color printers published in AD and place them in coma separated value text file so that it can easily be imported to Excel and such.

On Error Resume Next
Const ADS_SCOPE_SUBTREE = 2
Dim aPPort
 
Set oWS = WScript.CreateObject("wscript.shell")
Set oFS = CreateObject("scripting.filesystemobject")
 
sFilePath = "C:\Support\PrintServerPrinters" & sComputer & ".tsv"
 
Set oFile = oFS.CreateTextFile(sFilePath, True)
 
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, driverName, portName from " _     
    & " 'LDAP://DC=YOURDOMAIN,DC=com' where objectClass='printQueue' and printColor=TRUE"  
objCommand.Properties("Page Size") = 4000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE 
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
 
'aPPort is an Array in this case that can apparently hold multiple IP address values.
Do Until objRecordSet.EOF
	sPName = objRecordSet.Fields("printerName").Value
	sPModel = objRecordSet.Fields("driverName").Value
	aPPort = objRecordSet.Fields("portName").Value
	oFile.WriteLine sPName & "," & sPModel & "," & aPPort(0)
    objRecordSet.MoveNext
    
Loop

Open in new window

0
 
LVL 17

Expert Comment

by:Jared Luker
ID: 21975735
Well done... thanks for sharing the code.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses
Course of the Month3 days, 19 hours left to enroll

601 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question