Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3431
  • Last Modified:

Enumerating Clustered Print Server Printers with WMI and VBS?

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
Hubasan
Asked:
Hubasan
  • 3
  • 3
1 Solution
 
Jared LukerCommented:
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
 
HubasanAuthor Commented:
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
 
Jared LukerCommented:
Is there any firewalls or special port blocking on those clustered machines that might be blocking WMI?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
HubasanAuthor Commented:
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
 
HubasanAuthor Commented:
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
 
Jared LukerCommented:
Well done... thanks for sharing the code.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now