Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

output VBS script to CSV file

Posted on 2013-05-22
3
Medium Priority
?
533 Views
Last Modified: 2013-05-22
I need to run a script and have the results outputted to c:\file.csv
Here is the script can anyone tell me what I need to add to output to CSV

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery( _
    "SELECT * FROM Win32_BootConfiguration",,48)
For Each objItem in colItems
    Wscript.Echo "-----------------------------------"
    Wscript.Echo "Win32_BootConfiguration instance"
    Wscript.Echo "-----------------------------------"
    Wscript.Echo "ConfigurationPath: " & objItem.ConfigurationPath
Next
0
Comment
Question by:Sid_F
[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
3 Comments
 
LVL 42

Assisted Solution

by:sedgwick
sedgwick earned 1000 total points
ID: 39188602
Set objFSO=CreateObject("Scripting.FileSystemObject")
outFile="c:\test\result.csv"
Set objFile = objFSO.CreateTextFile(outFile,True)
objFile.Write "ConfigurationPath" & vbCrL
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery( _
    "SELECT * FROM Win32_BootConfiguration",,48)
For Each objItem in colItems
    Wscript.Echo "-----------------------------------"
    Wscript.Echo "Win32_BootConfiguration instance"
    Wscript.Echo "-----------------------------------"
    Wscript.Echo "ConfigurationPath: " & objItem.ConfigurationPath
objFile.Write objItem.ConfigurationPath & vbCrL
Next
objFile.Close
0
 
LVL 57

Accepted Solution

by:
Bill Prew earned 1000 total points
ID: 39188611
Const ForWriting = 2 ' Open file read write
Const OutputFile = "c:\temp\file.csv"

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objWriter = objFSO.OpenTextFile(OutputFile, ForWriting, True)

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery( _
    "SELECT * FROM Win32_BootConfiguration",,48)
For Each objItem in colItems
    objWriter.WriteLine "-----------------------------------"
    objWriter.WriteLine "Win32_BootConfiguration instance"
    objWriter.WriteLine "-----------------------------------"
    objWriter.WriteLine "ConfigurationPath: " & objItem.ConfigurationPath
Next 

objWriter.Close

Open in new window

~bp
0
 
LVL 6

Author Closing Comment

by:Sid_F
ID: 39189393
thanks
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
The purpose of this article is to demonstrate how we can use conditional statements using Python.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

721 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