Solved

Enumerating Clustered Print Server Printers with WMI and VBS?

Posted on 2008-06-26
9
3,340 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
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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

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…
When you try to share a printer , you may receive one of the following error messages. Error message when you use the Add Printer Wizard to share a printer: Windows could not share your printer. Operation could not be completed (Error 0x000006…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

805 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