Solved

output VBS script to CSV file

Posted on 2013-05-22
3
527 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
3 Comments
 
LVL 42

Assisted Solution

by:sedgwick
sedgwick earned 250 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 53

Accepted Solution

by:
Bill Prew earned 250 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Compile Error 7 53
Problem to refer to value 8 50
Using VBscript & RegEx, how can I match lines starting with Oracle word 17 59
VBScript on Html 11 20
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
This article will show, step by step, how to integrate R code into a R Sweave document
This video teaches viewers about errors in exception handling.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

832 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