Solved

Enumerating Clustered Print Server Printers with WMI and VBS?

Posted on 2008-06-26
9
3,315 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
9 Comments
 
LVL 17

Expert Comment

by:Jared Luker
Comment Utility
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
Comment Utility
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
Comment Utility
Is there any firewalls or special port blocking on those clustered machines that might be blocking WMI?
0
Why do Marketing keep bothering you?

Is your marketing department constantly asking for new email signature updates? Are they requesting a different design for every department? Do they need yet another banner added? Don’t let it get you down! There is an easy way to manage all of these requests...

 
LVL 7

Author Comment

by:Hubasan
Comment Utility
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
Comment Utility
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
Comment Utility
Well done... thanks for sharing the code.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

This is my 3rd article on SCCM in recent weeks, the 1st (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/Server/Windows_Server_2008/A_4466-A-beginners-guide-to-installing-SCCM2007-on-Windows-2008-R2-Server.html) dealing with installat…
Remote Apps is a feature in server 2008 which allows users to run applications off Remote Desktop Servers without having to log into them to run the applications.  The user can either have a desktop shortcut installed or go through the web portal to…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

728 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now