I'm looking for a solution to quering my 4 print servers which have 1400 printers on each one.
The script works great on the initial server but when it tries to go to next server (Server02), it comes back with the RPC error. It then continues the loop and moves to the 3rd server (Server03) and captures all the printers on it, it then moves to the 4th server (Server04) and it comes back with the RPC error.
I'm not familiar with CreateObject("PrintMaster.PrintMaster.1"), therefore I'm still trying to figure out why the data capture works on some but not all print servers.
CODE
========
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set dtDateTime = CreateObject("WbemScripting.SWbemDateTime")
sYear = Year(Date-1)
sMonth = Month(Date-1)
sDay = Day(Date-1)
sLogFile = "c:\" & sYear & "-" & sMonth & "-" & sDay & "_Prt_Export.log"
Set oFile = oFSO.OpenTextFile(sLogFile, ForWriting, True, 0)
If Err.Number <> 0 Then
msgbox "File " & sLogFile & " cannot be opened",, "ERROR", vbCritical
Wscript.Quit(1)
End If
set oMaster = CreateObject("PrintMaster.PrintMaster.1")
If Err.Number <> 0 Then
oFile.writeline (vbCrLf & "* Error (PrintMaster.1):" & Hex(Err.Number) & " " & Err.Description & vbCrLf)
Err.Clear
End If
set oPrinter = CreateObject("Printer.Printer.1")
If Err.Number <> 0 Then
oFile.writeline (vbCrLf & "* Error (Set Printer.1):" & Hex(Err.Number) & " " & Err.Description & vbCrLf)
Err.Clear
End If
oFile.writeline ("Server" & vbTab & _
"PrinterName" & vbTab & _
"PortName" & vbTab & _
"Status" & vbTab & _
"Jobcount" & vbTab & _
"JobDate" & vbTab & _
"Attributes" & vbTab & _
"StartTime" & vbTab & _
"UntilTime" & vbTab & _
"Verify")
k = 0
For i=0 to UBound(ArrServer)-1
Err.Clear
Set oWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & ArrServer(i) & "\root\cimv2")
If Err.Number <> 0 Then
oFile.writeline (vbCrLf & "* Error (Set oWMI):" & Hex(Err.Number) & " " & Err.Description & vbCrLf)
Err.Clear
End If
'############ - ERROR STARTS HERE!!
for each oPrinter in oMaster.Printers("\\" & ArrServer(i))
If Err.Number <> 0 Then
oFile.writeline (vbCrLf & "* Error (For oMaster.Printers):" & Hex(Err.Number) & " " & Err.Description & vbCrLf)
Err.Clear
Else
If k <> 0 then ReDim Preserve arrPrinter(10,UBound(arrPrinter,2) + 1)
RESULTS
============
1729 Server1 Printer01 Port01 Ready 0 N/A 64 60 60 0
* Error (For oMaster.Printers):800706BA The RPC server is unavailable.
>> Stay informed about: WMI-> oMaster.Printers 800706BA RPC server unavailable