Avatar of Willing2Learn_More
Willing2Learn_More
 asked on

VB Script to query printers and write to a .csv file on the network

OK. here is the issue. I need a script to query 12k computers for a certain printer server. Then, if you have the certain print server exsists (\\PRINTSVRCC01) then I want it to write the information to a .csv file located on a network share. \\myserver\share\printresults.csv. The information should include the printer server name, print queue and their host name.

Below is a script that I am starting but could use some help. I am new to vb and not sure how to resolve this.



strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

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

For Each objPrinter in colInstalledPrinters
    Wscript.Echo "Name: " & objPrinter.Name
    Wscript.Echo "Location: " & objPrinter.Location
    Wscript.Echo "Default: " & objPrinter.Default
   Next

Const ForAppending = 8

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile _
    ("\\myserver\share\printresults.csv", ForAppending, True)

Set objWMIService=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
    strComputer & "\root\cimv2")
Set colServices = objWMIService.ExecQuery("Select * from Win32_Service")

For Each objService in colServices    
    objTextFile.WriteLine(objService.DisplayName & vbTab & _
        objService.State)
Next
objTextFile.Close
VB Script

Avatar of undefined
Last Comment
RobSampson

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
RobSampson

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes