Link to home
Start Free TrialLog in
Avatar of Hubasan
HubasanFlag for United States of America

asked on

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

Avatar of Jared Luker
Jared Luker
Flag of United States of America image

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?
Avatar of Hubasan

ASKER

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.
Is there any firewalls or special port blocking on those clustered machines that might be blocking WMI?
Avatar of Hubasan

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of Hubasan
Hubasan
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Well done... thanks for sharing the code.