-
Tidy Script Up
Basically collates all the info I require, appends said info to a text file, changes the file extension to a csv file.
Currently no checks regards to directory to ensure there is a directory named logs ( that is easy enough to do )
Is there anyway of tidying this up etc
Code:
const HKEY_CURRENT_USER = &H80000001const HKEY_LOCAL_MACHINE = &H80000002
Const ForReading = 1, ForWriting = 2, ForAppending = 8
strComputer = "."
Set StdOut = WScript.StdOut
Dim username, Model, serial, asset, hdd, manu
Dim strRAM
dim filesys, filetxt
Dim usbPath, FullPath
Set objNetwork = CreateObject("Wscript.Network")
username = objNetwork.username
strComputer = objNetwork.ComputerName
usbPath = Replace(WScript.ScriptFullName, WScript.ScriptName, "")
FullPath = usbPath & "logs\"
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_ComputerSystem",,48)
For Each Item In colItems
manu = Item.Manufacturer
model = Item.Model
Next
Set colItems = objWMIService.ExecQuery("Select * from Win32_BIOS")
For Each objItem in colItems
serial = objItem.SerialNumber
Next
Set colItems = objWMIService.ExecQuery("Select * from Win32_SystemEnclosure")
For Each objItem in colItems
asset = objItem.SMBIOSAssetTag
Next
Set objRegistry = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
strKeyPath = "HARDWARE\DESCRIPTION\System\CentralProcessor\0"
strValue = "ProcessorNameString"
objRegistry.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValue,strScriptStatus
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_PhysicalMemory",,48)
For Each objItem in colItems
strRAM = FormatNumber((objItem.Capacity/1048576)/1024,2) & " Gb RAM"
Next
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colDisks = objWMIService.ExecQuery("Select * from Win32_LogicalDisk")
For Each objDisk in colDisks
If objDisk.DeviceID = "C:" Then
Select Case objDisk.DriveType
Case 3
hdd = Int(objDisk.Size/1073741824) & " Gb"
End Select
End If
Next
Set filesys = CreateObject("Scripting.FileSystemObject")
Set filetxt = filesys.OpenTextFile(FullPath & ucase(username) & ".txt" , ForAppending, True)
filetxt.WriteLine "Username,Manufacturer,Serial Number,Model,Computer Name,RAM,HDD,Asset Tag,Processor"
filetxt.WriteLine ucase(username) & "," & manu & "," & serial & "," & model & "," & strComputer & "," & strRAM & "," & hdd & "," & asset & "," & strScriptStatus
filetxt.Close
msgbox ucase(username) & vbcrlf & manu & vbcrlf & model & vbcrlf & serial & vbcrlf & asset & vbcrlf & vbcrlf & strComputer & vbcrlf & strScriptStatus & vbcrlf & strRAM & vbcrlf & hdd
wscript.sleep 1000
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set FileList = objWMIService.ExecQuery ("ASSOCIATORS OF {Win32_Directory.Name='" & usbPath & "logs" & "'} Where ResultClass = CIM_DataFile")
For Each objFile In FileList
If objFile.Extension = "txt" Then
strNewName = objFile.Drive & objFile.Path & _
objFile.FileName & "." & "csv"
errResult = objFile.Rename(strNewName)
If errResult <> "0" Then
Wscript.Echo errResult
else
Wscript.Echo "Conversion to CSV Completed"
End If
End If
Next
Set objMemory = Nothing
Set objWMIService = Nothing
-