[Last Call] Learn how to a build a cloud-first strategyRegister Now

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

VBSCRIPT to enumerate all ip printers on remote computers

HELP!

I need to create a script that will allow me to input a list of PC's remotely and then have the script enumerate all the IP Printers for each PC and output that to a text file!!

Thanks,
Mike
0
mikeeubank
Asked:
mikeeubank
1 Solution
 
QueueItCommented:
Try this...
Create and paste the following in a vbs file:

'START OF FILE

Option Explicit

Const ListOnlyIPPrinters = true

Dim LogFileName
LogFileName = WScript.CreateObject("WScript.Shell").SpecialFolders("Desktop") & "\printer_log.txt"

DeleteFile( LogFileName )

Dim sList
Dim aList
Dim sPC

sList = InputBox("Enter list of computers comma delimited:", "Printer List")

aList = Split(sList, ",")

For Each sPC in aList
      sPC = Trim(sPC)

      ListIPPrinters( sPC )

      Call LogToFile( LogFileName, "")
Next

msgbox "done"

Sub ListIPPrinters( ComputerName )
      Dim objWMIService, colInstalledPrinters, objPrinter

      ON ERROR RESUME NEXT
      Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & ComputerName & "\root\cimv2")
      If ERR.NUMBER <> 0 Then
            Call LogToFile( LogFileName, "Problem connecting to " & ComputerName & ". " & Err.Description)
            Err.Clear
            Exit Sub
      End If
      ON ERROR GOTO 0

      Call LogToFile( LogFileName, "Connected to " & ComputerName)

      Set colInstalledPrinters = objWMIService.ExecQuery("Select * from Win32_Printer")

      Call LogToFile( LogFileName, vbTab & "Found " & colInstalledPrinters.count & " printers.")

      For Each objPrinter in colInstalledPrinters
            If ListOnlyIPPrinters Then
                  If instr(1, objPrinter.PortName, "IP_", 1) = 1 Then
                        Call LogToFile( LogFileName, vbTab & objPrinter.Name & " - " & objPrinter.PortName)
                  End If
            Else
                  Call LogToFile( LogFileName, vbTab & objPrinter.Name & " - " & objPrinter.PortName)
            End If
      Next
End Sub

Sub LogToFile( sFileName, sText )
      Dim FSO, File
      Set FSO = CreateOBject("Scripting.FileSystemObject")
      Set File = FSO.OpenTextFile( sFileName, 8, True)
      File.WriteLine( sText )
      File.Close
      Set File = Nothing
      Set FSO = Nothing
End Sub

Sub DeleteFile( sFileName )
      Dim FSO
      Set FSO = CreateOBject("Scripting.FileSystemObject")
      If FSO.FileExists( sFileName ) Then
            FSO.DeleteFile( sFileName )
      End If
      Set FSO = Nothing
End Sub

'END OF FILE.

Just double click on the file to run.
It will prompt you for a list of computers comma delimited (pc1,pc2,etc)
It will then try to connect to each computer using WMI and list all printers to a text file on your desktop and prompt you when it's done.

Some if this code is from http://www.cruto.com/resources/vbscript/vbscript-examples/printing/client/List-Printer-Connections.asp

Let me know if this works for you.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

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