Option Explicit 'On Error Resume Next dim outputstring, computermodel, pcmake, pcmodel, cpu, ram, hddcapacity, hddfree, serialno, macaddress, operatingsystem, csvoutput, csvoutput2 dim stcomputer, colitems, objItem, colcpu, colPhysicalMemory, objPhysicalMemory, intMemory, colDisks, objhdd dim colComputerSystem, colOperatingSystems, objOperatingSystem, colBIOS, objBIOS, colnicconfig, objnicconfig dim objwmiservice, hddtemp, weidata, colWSA, operatingsystemno, Lastuser, oreg, spath, svalue, strvalue, svaluename dim adoutputstring, adoRecordset, adoConnection, objRootDSE, objNetwork, objComputer, existing, basedata dim pcname, wshShell, strDirectory, strFile, objFSO, objFolder, objFile, objTextFile, myDateString dim colnet,objnet, linkspeed, objWMIService2, strline, strNewContents, strDirectory2, strFile2, objfolder2, objfile2 stcomputer = "." myDateString = Date() Set objRootDSE = GetObject("LDAP://RootDSE") Set objNetwork = WScript.CreateObject("WScript.Network") Set objWMIService = GetObject("winmgmts:\\" & stcomputer & "\root\CIMV2") Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem") Set colcpu = objWMIService.ExecQuery("Select * from Win32_Processor") Set colPhysicalMemory = objWMIService.ExecQuery("Select * From Win32_PhysicalMemory") set coldisks = objWMIService.ExecQuery("Select * From Win32_LogicalDisk") Set colComputerSystem = objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem") Set colOperatingSystems = objWMIService.ExecQuery ("Select * from Win32_OperatingSystem") Set colBIOS = objWMIService.ExecQuery("Select * From Win32_BIOS") Set colnicconfig = objWMIService.ExecQuery("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True") Set colWSA = objWMIservice.ExecQuery("Select * From Win32_WinSAT") Set adoConnection = CreateObject("ADODB.Connection") adoConnection.Provider = "ADsDSOObject" adoConnection.Open "Active Directory Provider" Set adoRecordset = adoConnection.Execute(";(&(objectCategory=Computer)(name=" & objNetwork.Computername & "));adspath;subtree") Set wshShell = WScript.CreateObject( "WScript.Shell" ) Set objWMIService2 = GetObject("winmgmts:\\" & stComputer & "\root\WMI") Set colnet = objWMIService2.ExecQuery("SELECT * FROM MSNdis_LinkSpeed",,48) basedata= "MAC Address,Network Adapter,IP Address,Computer Name,GUID/UUID,GUID/UUID Mac Address Conversion,Total RAM Memory,Sid,RAM Memory Bank Label,RAM Memory Capacity,RAM Memory Device Locator,RAM Memory Manufacturer,Computer Manufacturer,Computer Model,Computer Serial,Motherboard Manufacturer,Motherboard Model,Motherboard Product,Motherboard Serial Number,Motherboard Version,Hard Disk Drive Letter,Hard Disk Size,Hard Disk Free Space,Hard Disk Volume Serial Number,Hard Disk Manufacturer,Hard Disk Model,Hard Disk Device ID,Hard Disk Interface Type,Hard Disk Partitions,Hard Disk Total Cylinders,Hard Disk Total Heads,Hard Disk Total Sectors,Hard Disk Total Tracks,Hard Disk Tracks Per Cylinder,Processor Name,Processor Type,Processor Family,Sound Card Manufacturer,Sound Card Product Name,Sound Card Description,Sound Card Name,Video Card Name,Video Card Setting ID,Floppy Manufacturer,Floppy Name,Floppy Device ID,CDROMCaptionSet,CDROMDescriptionSet,CDROMDeviceIDSet,CDROMDriveSet,CDROMManufacturerSet,CDROMNameSet,BIOS Version,Dell Service Tag,Date of Log,Time of Log" 'write file 1 location pcname = wshShell.ExpandEnvironmentStrings( "%COMPUTERNAME%" ) strDirectory = "\\gateway\logs$\test\" strFile = pcname & ".csv" 'write file 2 location strDirectory2 = "\\gateway\logs$\test\" strFile2 = "inventorylog.csv" 'make-model For Each objItem In colItems computermodel= objItem.Manufacturer & " " & objItem.Model pcmake=objItem.Manufacturer pcmodel=objItem.Model 'wscript.echo computermodel Next ' Create the File System Object Set objFSO = CreateObject("Scripting.FileSystemObject") 'cpu info For Each objItem in colcpu cpu = objItem.Name 'wscript.echo cpu Next 'ram If Not colPhysicalMemory Is Nothing Then intMemory = 0 For Each objPhysicalMemory In colPhysicalMemory intMemory = intMemory + Int(objPhysicalMemory.Capacity) Next ram = (intMemory / 1024 / 1024 ) & " MB" 'wscript.echo ram End If 'hdd capacity for each objhdd in coldisks If objhdd.DeviceID = "C:" Then hddcapacity = int(objhdd.Size/1073741824) & " GB" hddfree = int(objhdd.freespace/1073741824) & " GB" 'wscript.echo hddfree end if next 'windows version For Each objOperatingSystem in colOperatingSystems operatingsystem = objOperatingSystem.Caption & " sp " & objOperatingSystem.ServicePackMajorVersion operatingsystemno = objOperatingSystem.Version 'wscript.echo operatingsystem Next 'serial no If Not colBIOS Is Nothing Then For Each objBIOS in colBIOS serialno = objBIOS.SerialNumber 'wscript.echo serialno Next End If 'mac address(s) If Not colnicconfig Is Nothing Then For Each objnicconfig in colnicconfig If macaddress <> "" Then macaddress = macaddress & " - " End If macaddress = macaddress & objnicconfig.MACAddress 'wscript.echo macaddress Next End If 'windows experience operatingsystemno = Left( operatingsystemno, 3 ) if operatingsystemno >5.5 then 'vista+ For Each objItem in colWSA 'weidata = "Overall -" & "na" & " - CPU - " & "na" & " - Memory - " & "na" & " - Graphics - " & "na" & " - Gaming graphics - " & "na" & " - hdd - " & "na" weidata = "Overall -" & objItem.WinSPRLevel & " - CPU - " & objItem.CPUScore & " - Memory - " & objItem.MemoryScore & " - Graphics - " & objItem.GraphicsScore & " - Gaming graphics - " & objItem.D3DScore & " - hdd - " & objItem.DiskScore next else 'xp- weidata = "Overall -" & "na" & " - CPU - " & "na" & " - Memory - " & "na" & " - Graphics - " & "na" & " - Gaming graphics - " & "na" & " - hdd - " & "na" end if 'last user if operatingsystemno >5.5 then 'vista+ Const HKLM = &H80000002 'HKEY_LOCAL_MACHINE Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & stcomputer & "/root/default:StdRegProv") If Err.Number <> 0 Then On Error Goto 0 Else On Error Goto 0 sPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI" sValueName = "LastLoggedonUser" If oReg.GetStringValue(HKLM, sPath, sValueName, sValue) = 0 Then lastuser = sValue Else lastuser = "unknown" & stcomputer End If End If else 'xp- Const HKEY_LOCAL_MACHINE = &H80000002 Set oreg=GetObject("winmgmts:\\" & stComputer & "\root\default:StdRegProv") spath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\WinLogon" svalue = "DefaultUserName" oreg.GetStringValue HKEY_LOCAL_MACHINE, spath, svalue, strValue lastuser=strvalue svalue = "DefaultDomainName" oreg.GetStringValue HKEY_LOCAL_MACHINE, spath, svalue, strValue lastuser = strvalue & "\" & lastuser end if 'Scans data for Net Speed For Each objnet in colnet 'Removes "slow/unused links" if objnet.NdisLinkSpeed/10 > 1000 then linkspeed= objnet.NdisLinkSpeed/10000 & " Mbps" & "-" & linkspeed '& "-" & objnet.NdisLinkSpeed/10000 & " Mbps" end if next 'concatanate data for output outputstring = computermodel & "," & cpu &"," & ram &"," & hddcapacity& "," & serialno & "," & macaddress & "," csvoutput = pcname & "," & computermodel & "," & cpu &"," & ram &"," & hddcapacity& "," & hddfree & "," & serialno & "," & operatingsystem & "," & macaddress & "," & weidata & "," & Lastuser & "," & linkspeed &"," & myDateString &"," csvoutput2 = macaddress & ", "&" ,"& "," & pcname & "," & "," & "," & ram &"," &"," &"," &"," &"," &"," & pcmake & "," & pcmodel & "," & serialno & "," & "," & "," & "," & "," & "," & "," & hddcapacity & "," & hddfree & "," & "," & "," & "," & "," & "," & "," & "," & "," & "," & "," & "," & cpu & "," & "," & "," & "," & "," & "," & "," & "," & "," & "," & "," & "," & "," & "," & "," & "," & "," & "," & "," & "dell," & myDateString & "," ' wscript.echo outputstring ' Check that the strDirectory folder exists If objFSO.FolderExists(strDirectory) Then Set objFolder = objFSO.GetFolder(strDirectory) Else Set objFolder = objFSO.CreateFolder(strDirectory) 'WScript.Echo "Just created " & strDirectory End If If objFSO.FileExists(strDirectory & strFile) Then Set objFolder = objFSO.GetFolder(strDirectory) Else Set objFile = objFSO.CreateTextFile(strDirectory & strFile) 'Wscript.Echo "Just created " & strDirectory & strFile End If set objFile = nothing set objFolder = nothing ' OpenTextFile Method needs a Const value ' ForAppending = 8 ForReading = 1, ForWriting = 2 Const ForAppending = 2 Set objTextFile = objFSO.OpenTextFile _ (strDirectory & strFile, ForAppending, True) ' Writes result every time you run this VBScript objTextFile.WriteLine(csvoutput) objTextFile.Close If Err.Number <> 0 Then MsgBox "Query Error: " & Err.Description WScript.Quit End If '******************************************** '2nd file '******************************************** ' Check that the strDirectory folder exists If objFSO.FolderExists(strDirectory2) Then Set objFolder2 = objFSO.GetFolder(strDirectory2) Else Set objFolder2 = objFSO.CreateFolder(strDirectory2) 'WScript.Echo "Just created " & strDirectory2 & strfile2 & "bit1" End If If objFSO.FileExists(strDirectory2 & strFile2) Then Set objFolder2 = objFSO.GetFolder(strDirectory2) Else Set objFile2 = objFSO.CreateTextFile(strDirectory2 & strFile2) 'Wscript.Echo "Just created " & strDirectory2 & strFile2 &"bit2" objfile2.close Set objFile2 = objFSO.OpenTextFile((strDirectory2 & strFile2), ForWriting) objFile2.WriteLine(basedata) objfile2.close End If Const ForReading = 1 Const ForWriting = 2 Set objFSO = CreateObject("Scripting.FileSystemObject") Set objFile2 = objFSO.OpenTextFile((strDirectory2 & strFile2), ForReading) Do Until objFile2.AtEndOfStream strLine = objFile2.ReadLine If InStr(left(strLine,17), macaddress) = 0 Then strNewContents = strNewContents & strLine & vbCrLf End If Loop objFile2.Close Set objFile2 = objFSO.OpenTextFile((strDirectory2 & strFile2), ForWriting) objFile2.Write strNewContents objFile2.WriteLine(csvoutput2) objFile2.Close If Not adoRecordset.EOF Then Set objComputer = GetObject(adoRecordset.Fields(0).Value) existing = objcomputer.Description if left (existing,1) = "#" and not right (existing,1) = "#" then outputstring = existing & " : " & outputstring & "#" if left (existing,1) = "#" and right (existing,1) = "#" then 'msgbox "data" wscript.quit end if if not objComputer.Description = outputstring then 'msgbox "diff" objComputer.Put "description", outputstring objComputer.SetInfo else 'msgbox "matches" end if End If If Err.Number <> 0 Then MsgBox "Write Error: " & Err.Description WScript.Quit End If