Solved

output VBS script to CSV file

Posted on 2013-05-22
3
528 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 54

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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
This video teaches viewers about errors in exception handling.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

820 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