Solved

output VBS script to CSV file

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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
The viewer will learn how to implement Singleton Design Pattern in Java.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

738 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