This script will connect remotely to computers listed in a text file and inventory the computer processor, memory, IP, and Hard drive space. The portion that inventorys the hard drive space was written by some else and the rest I got it from MS website along with other sites. This script will dump the info to a csv file which can then be imported into a database if you want. Being new to scripting I haven’t touched databases yet but see its importance. Again, not much commenting on the script but it works really well.
‘========================================================================
‘Script to inventory server Processor, Memory, IP, and Hard drive space
‘========================================================================
Set ObjFso = CreateObject(”scripting.filesystemobject”)
Set objTSIn = objFSO.OpenTextFile(”C:\Temp\Domain\DomainComputers.txt”)
Set objTSOut = objFSO.CreateTextFile(”c:\temp\Domain\ComputerReport.csv”,2, True)
objTSOut.Write(”Server Name” & Vbtab & “Operating System” & vbTab & “Serial Number” & vbTab & “Manufacturer” & vbtab & “Model” & vbTab & “Memory” & vbTab & “# of Processors” & vbTab & “Processor Type” & vbTab & “IP Address” & vbtab & “Logical Disk” & vbcr)
‘Start Loop
Do While Not objTSIn.AtEndOfStream
On Error Resume next
strComputer = objTSIn.ReadLine
’Connect to remote computer
Set objWMIService = GetObject(”winmgmts:” _
& “{impersonationLevel=impersonate}!\\” & strComputer & “\root\cimv2″)
‘Log failed connections
If Err.Number <> 0 Then
Set objLogOut = objFSO.CreateTextFile(”C:\Temp\Domain\log.txt”,2, True)
objLogOut.Write(”Connection failed on: ” & strComputer & ” on ” & Now & vbCrLf)
’Continue with script if no error encounters
ElseIf Err.Number = 0 Then
‘OS info
Set colOSes = objWMIService.ExecQuery(”Select * from Win32_OperatingSystem”)
For Each objOS in colOSes
objTSOut.Write(strComputer & vbTab & objOS.Caption & ” SP ” & objOS.ServicePackMajorVersion & “.” & objOS.ServicePackMinorVersion & vbTab)
’Get Serial Number
Set oWMIService = GetObject(”winmgmts:\\” & strComputer & “\root\cimv2″)
Set colItems1 = objWMIService.ExecQuery(”SELECT * FROM Win32_BIOS”,,48)
For Each oItem In colItems1
objTSOut.Write(oItem.SerialNumber & vbTab)
’Get Total Physical memory
Set colSettings = objWMIService.ExecQuery(”Select * from Win32_ComputerSystem”)
For Each objComputer in colSettings
objTSOut.Write(objComputer.Manufacturer & vbTab & objComputer.Model & vbTab & Round((objComputer.TotalPhysicalMemory/1000000000),4) & vbTab & objComputer.NumberOfProcessors & vbTab )
’Get Processor Information
Set colItems = objWMIService.ExecQuery(”Select * from Win32_Processor”,,48)
For Each objItem in colItems
objTSOut.Write(objItem.Name & vbTab)
‘Get NETWORK ADAPTERS information
Set colIPItems = objWMIService.ExecQuery(”SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True”)
For Each objIPItem In colIPItems
strIPAddress = Join(objIPItem.IPAddress, “,”)
’WScript.Echo “IPAddress: ” & strIPAddress
objTSOut.Write(strIPAddress & vbtab)
’Get Logical Disk Size and Partition Information
Set colDisks = objWMIService.ExecQuery(”Select * from Win32_LogicalDisk Where DriveType = 3″)
For Each objDisk in colDisks
DriveLetter = objDisk.DeviceID
intFreeSpace = objDisk.FreeSpace
intTotalSpace = objDisk.Size
pctFreeSpace = intFreeSpace / intTotalSpace
objTSOut.Write(”DISK ” & objDisk.DeviceID & ” (” & objDisk.FileSystem & “) ” & Round((objDisk.Size/1000000000),4) & ” GB (”& Round((intFreeSpace/1000000000)*1.024,4) & ” GB Free Space)”) & ” “
Next
Next
Exit For ‘ Exits Win32_Processer loop
Next
Next
Next
Next
objTSOut.Write(vbCr)
End if
Loop
MsgBox “Script Finished”
0 Responses to “Inventory Hardware VBScript”