PDA

View Full Version : Export WMI script data to a txt file. (All)



Musashi
05-18-2004, 08:43 AM
Hi peeps,

I have a WMI script collecting data from PC's in our domain. I can't seem to find the right info on how to export all of the info the script picks up to a network share and into a txt file.

I would like each txt file name to be the PC name if poss....Please help!!

Thanks

Here is the script I have written.

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem",,48)
For Each objItem in colItems
Wscript.Echo "Caption: " & objItem.Caption
Wscript.Echo "CountryCode: " & objItem.CountryCode
Wscript.Echo "CSDVersion: " & objItem.CSDVersion
Wscript.Echo "CSName: " & objItem.CSName
Wscript.Echo "SystemDirectory: " & objItem.SystemDirectory
Wscript.Echo "SystemDrive: " & objItem.SystemDrive
Wscript.Echo "TotalVirtualMemorySize: " & objItem.TotalVirtualMemorySize
Wscript.Echo "TotalVisibleMemorySize: " & objItem.TotalVisibleMemorySize
Wscript.Echo "WindowsDirectory: " & objItem.WindowsDirectory
Wscript.Echo "TotalPhysicalMemory: " & objItem.TotalPhysicalMemory
Next

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_Processor",,48)
For Each objItem in colItems
Wscript.Echo "Name: " & objItem.Name
Wscript.Echo "MaxClockSpeed: " & objItem.MaxClockSpeed
Next

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_PhysicalMemory",,48)
For Each objItem in colItems
Wscript.Echo "Caption: " & objItem.Caption
Wscript.Echo "Capacity: " & objItem.Capacity
Wscript.Echo "DeviceLocator: " & objItem.DeviceLocator
Next

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_LogicalDisk",,48)
For Each objItem in colItems
Wscript.Echo "DeviceID: " & objItem.DeviceID
Wscript.Echo "FreeSpace: " & objItem.FreeSpace
Wscript.Echo "Size: " & objItem.Size
Next


Thanks!!

Chris

msearly
05-18-2004, 08:57 AM
Instead of outputting results to the screen via WScript.Echo, utilize the FileSystemObject to output to a file

Set fso = Scripting.FileSystemObject

You should be able to find ample support of the FileSystemObject from this forum and MSDN





Matt Early
Network Administrator
Prince Edward County Public Schools
Farmville, VA

Musashi
05-20-2004, 01:45 AM
thanks for that..!!!

Ok now ive got it going into a csv file on a network share..How do i get it to append the csv file by putting the data in a new column rather than overwriting the data made by the last PC to run the VBS file?

Many many thanks!!

here is the script I have so far..

On Error Resume Next

Set fso = CreateObject("Scripting.FileSystemObject")
Set tf = fso.CreateTextFile("\\shscc06\netlogon\pcaudit\PCAudit.csv", True)

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem",,48)
For Each objItem in colItems
tf.WriteLine(objItem.Caption)
tf.WriteLine(objItem.CountryCode)
tf.WriteLine(objItem.CSDVersion)
tf.WriteLine(objItem.CSName)
tf.WriteLine(objItem.SystemDirectory)
tf.WriteLine(objItem.SystemDrive)
tf.WriteLine(objItem.TotalVirtualMemorySize)
tf.WriteLine(objItem.TotalVisibleMemorySize)
tf.WriteLine(objItem.WindowsDirectory)
tf.WriteLine(objItem.TotalPhysicalMemory)
Next

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_Processor",,48)
For Each objItem in colItems
tf.WriteLine(objItem.Name)
tf.WriteLine(objItem.MaxClockSpeed)
Next

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_PhysicalMemory",,48)
For Each objItem in colItems
tf.WriteLine(objItem.Caption)
tf.WriteLine(objItem.Capacity)
tf.WriteLine(objItem.DeviceLocator)
Next

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_LogicalDisk",,48)
For Each objItem in colItems
tf.WriteLine(objItem.DeviceID)
tf.WriteLine(objItem.FreeSpace)
tf.WriteLine(objItem.Size)
Next


Thanks

Chris

hwolek
05-20-2004, 11:32 PM
Hi
Put the following two lines in your script and delete the line with CreateTextFile.
const ForAppending = 8
set tf = fso.OpenTextFile(("\\shscc06\netlogon\pcaudit\PCAudit.csv", ForAppending, True)
Heinz