Solved

output VBS script to CSV file

Posted on 2013-05-22
3
524 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
Comment Utility
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 51

Accepted Solution

by:
Bill Prew earned 250 total points
Comment Utility
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 5

Author Closing Comment

by:Sid_F
Comment Utility
thanks
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Copy Files - Python 7 52
Running Visio Macro from VBS File 3 32
recursion example 16 66
Using VB6 to write Excel Spreadsheets - 5 15
Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.   So …
The purpose of this article is to demonstrate how we can use conditional statements using Python.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

763 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now