Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Enumerating Clustered Print Server Printers with WMI and VBS?

Posted on 2008-06-26
9
Medium Priority
?
3,424 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
9 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
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…

618 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