Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Export results from a VB Script

Posted on 2015-02-05
4
Medium Priority
?
90 Views
Last Modified: 2015-02-19
Can someone modify this script to export the results to an excel CSV file? Also is there a way to modify this to work on multiple computers?

strComputer = "atl-ps-01"

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colPrinters = objWMIService.ExecQuery("Select * From Win32_Printer")
     
For Each objPrinter in colPrinters
    If objPrinter.Attributes And 64 Then 
        strPrinterType = "Local"
    Else
        strPrinterType = "Network"
    End If
    Wscript.Echo objPrinter.Name & " -- " & strPrinterType
Next

Open in new window

0
Comment
Question by:Edward Pamias
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 58

Accepted Solution

by:
Bill Prew earned 2000 total points
ID: 40592737
Give this a try.  It takes in a text file of the names of the computers to look at, and outputs a CSV with the results.  Adjust the file names near the top of these two files.

' Define needed constants
Const ForReading = 1
Const ForWriting = 2
Const TriStateUseDefault = -2

' Define input and output file names
Const Infile = "B:\EE\EE28611267\filein.txt"
Const Outfile = "B:\EE\EE28611267\fileout.csv"

' Create file system object
Set objFSO = CreateObject("Scripting.FileSystemObject")

' Open input and output files
Set objInfile = objFSO.OpenTextFile(Infile, ForReading, False, TriStateUseDefault)
Set objOutfile = objFSO.OpenTextFile(Outfile, ForWriting, True)

' Write out header line for CSV
objOutfile.WriteLine "ComputerName,PrinterName,PrinterType"

' Read input file line by line
Do While Not objInfile.AtEndOfStream
   ' Read the next line
   strComputer = objInfile.ReadLine

   Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

   Set colPrinters = objWMIService.ExecQuery("Select * From Win32_Printer")
        
   For Each objPrinter in colPrinters
       If objPrinter.Attributes And 64 Then
           strPrinterType = "Local"
       Else
           strPrinterType = "Network"
       End If
       objOutfile.WriteLine strComputer & "," & Quote(objPrinter.Name) & "," & strPrinterType
   Next

   Set colPrinters = Nothing
   Set objWMIService = Nothing

Loop

' Cleanup and end
objInfile.Close
objOutfile.Close
Set objInfile = Nothing
Set objOutfile = Nothing
Set objFSO = Nothing

' Add surrounding double quotes to a string
Function Quote(s)
   Quote = Chr(34) & s & Chr(34)
End Function

Open in new window

~bp
0
 
LVL 19

Author Comment

by:Edward Pamias
ID: 40619639
This worked great! Thanks!
0
 
LVL 19

Author Closing Comment

by:Edward Pamias
ID: 40619643
This script worked great! Thanks!
0
 
LVL 58

Expert Comment

by:Bill Prew
ID: 40619964
Welcome.

~bp
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
This article will show, step by step, how to integrate R code into a R Sweave document
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
Suggested Courses

609 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