Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - Pls help me create a CSV named from a varible in VBS

Reply
 
Old 11-19-2008   #1 (permalink)
GazzaJagman


 
 

Pls help me create a CSV named from a varible in VBS

Hi,
I'm trying to create a csv file that is named after the data I'm trying to
pass data to.
I want a script that finds the server hostname and then creates a CSV file
based on that name. I'm using VBS and WMI to find the machine's host name and
I'll be adding a load more objects later (which i why I chose to use WMI).
This script will eventually form an audit of a server. I know how to create a
CSV file and pass data to it, I just can't seem to work out how to rename the
file as a varible:

On Error Resume Next
Set objFS = CreateObject("Scripting.FileSystemObject")
Set objNewFile = objFS.CreateTextFile("Audit.csv")

'HostName
strComputer = "."
Set HN = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = HN.ExecQuery( _
"SELECT * FROM Win32_OperatingSystem",,48)
Set HostName = objItem.CSName
For Each objItem in colItems
Wscript.Echo objItem.CSName & ","
Next

objFile.Close

Can anyone help me?

Regards,

Gareth Cooper

--
"Science is what we hope for...Technology is what we get stuck with"

My System SpecsSystem Spec
Old 11-19-2008   #2 (permalink)
GazzaJagman


 
 

RE: Pls help me create a CSV named from a varible in VBS

opps...
I had an Echo there when I needed a Write,

For Each objItem in colItems
objNewFile.Write objItem.CSName & ","

--
"Science is what we hope for...Technology is what we get stuck with"


"GazzaJagman" wrote:
Quote:

> Hi,
> I'm trying to create a csv file that is named after the data I'm trying to
> pass data to.
> I want a script that finds the server hostname and then creates a CSV file
> based on that name. I'm using VBS and WMI to find the machine's host name and
> I'll be adding a load more objects later (which i why I chose to use WMI).
> This script will eventually form an audit of a server. I know how to create a
> CSV file and pass data to it, I just can't seem to work out how to rename the
> file as a varible:
>
> On Error Resume Next
> Set objFS = CreateObject("Scripting.FileSystemObject")
> Set objNewFile = objFS.CreateTextFile("Audit.csv")
>
> 'HostName
> strComputer = "."
> Set HN = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
> Set colItems = HN.ExecQuery( _
> "SELECT * FROM Win32_OperatingSystem",,48)
> Set HostName = objItem.CSName
> For Each objItem in colItems
> Wscript.Echo objItem.CSName & ","
> Next
>
> objFile.Close
>
> Can anyone help me?
>
> Regards,
>
> Gareth Cooper
>
> --
> "Science is what we hope for...Technology is what we get stuck with"
My System SpecsSystem Spec
Old 11-19-2008   #3 (permalink)
GazzaJagman


 
 

RE: Pls help me create a CSV named from a varible in VBS

Sorted! I worked it out through trial and error (mostly errors).
I used:

On Error Resume Next

Set objFS = CreateObject("Scripting.FileSystemObject")

Dim strComputer

'HostName'
strComputer = "."
Set HN = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = HN.ExecQuery( _
"SELECT * FROM Win32_OperatingSystem",,48)
For Each objItem in colItems
Set objNewFile = objFS.CreateTextFile(objItem.CSName & ".CSV")
objNewFile.WriteLine "HostName, "
objNewFile.Write objItem.CSName & ","
Next

objNewFile.Close

This script looks up a Server's hostname and then creates a CSV file using
the Hostname as a filename. It then populates the CSV file with a heading of
Hostname,
followed by the entry.

Regards,

Gareth Cooper
--
"Science is what we hope for...Technology is what we get stuck with"


"GazzaJagman" wrote:
Quote:

> opps...
> I had an Echo there when I needed a Write,
>
> For Each objItem in colItems
> objNewFile.Write objItem.CSName & ","
>
> --
> "Science is what we hope for...Technology is what we get stuck with"
>
>
> "GazzaJagman" wrote:
>
Quote:

> > Hi,
> > I'm trying to create a csv file that is named after the data I'm trying to
> > pass data to.
> > I want a script that finds the server hostname and then creates a CSV file
> > based on that name. I'm using VBS and WMI to find the machine's host name and
> > I'll be adding a load more objects later (which i why I chose to use WMI).
> > This script will eventually form an audit of a server. I know how to create a
> > CSV file and pass data to it, I just can't seem to work out how to rename the
> > file as a varible:
> >
> > On Error Resume Next
> > Set objFS = CreateObject("Scripting.FileSystemObject")
> > Set objNewFile = objFS.CreateTextFile("Audit.csv")
> >
> > 'HostName
> > strComputer = "."
> > Set HN = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
> > Set colItems = HN.ExecQuery( _
> > "SELECT * FROM Win32_OperatingSystem",,48)
> > Set HostName = objItem.CSName
> > For Each objItem in colItems
> > Wscript.Echo objItem.CSName & ","
> > Next
> >
> > objFile.Close
> >
> > Can anyone help me?
> >
> > Regards,
> >
> > Gareth Cooper
> >
> > --
> > "Science is what we hope for...Technology is what we get stuck with"
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Re: re-named folders by WLM Live Mail
Un-named trojan Live Messenger
Files named WindowsLiveContact Vista General
Local $varible scope? PowerShell
Multiple Named Networks Vista networking & sharing


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46