PDA

View Full Version : VBS send to file



Moordoom
02-17-2006, 09:34 AM
I need to get some information from about 1200 PCs across our WAN. The info is the User name, Computer name and Service tag (They are all Dells). I use the following script to get my info

'--------------------------------------------
' Service Tag Machine Name Save script

Set WshNetwork = WScript.CreateObject("WScript.Network")

on error resume next
strComputer = "."
Set objWMIservice = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
set colitems = objWMIservice.ExecQuery("Select * from Win32_BIOS",,48)
For each objitem in colitems
WScript.Echo "Computer Name = " & WshNetwork.ComputerName & VBCrLf _
& "User Name = " & WshNetwork.UserName & VBCrLf _
& "Dell Service Tag: " & objitem.serialnumber

'
NEXT
'----------------------------------------------

What I need help with is I need to append this information to a file (txt or xls). This way I can push this script out to all my PCs and retrieve this information.

Any help out there available?

jdharm
02-17-2006, 11:21 AM
This creates and appends to the end of the contents of a comma delimited text file. The changes are in bold, the variables you need to change to your needs in blue:




'--------------------------------------------
' Service Tag Machine Name Save script

Const ForReading=1, ForWriting=2, ForAppending=8

Set WshNetwork = WScript.CreateObject("WScript.Network")

on error resume next
strComputer = "."
Set objWMIservice = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
set colitems = objWMIservice.ExecQuery("Select * from Win32_BIOS",,48)
For each objitem in colitems
Set fso=CreateObject("Scripting.FileSystemObject")
Set f=fso.OpenTextFile("<font color=blue>\\&lt;path&gt;\log.txt</font color=blue>",ForAppending,True)
f.Write WshNetwork.Computername & _
"," & WshNetwork.UserName & _
"," & objitem.serialnumber & vbCrLf
f.Close

'
NEXT
'----------------------------------------------


Josh
<a target="_blank" href=http://www.jdharm.com>www.jdharm.com</a>

motoflop
02-17-2006, 11:24 AM
Does this help:

Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim fso, f
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile("testfile.txt", ForWriting, True)
f.Write "Hello world!" & vbCrLf
f.Write "Hello world!" & vbCrLf
f.Write "Hello world!" & vbCrLf
f.Close