Batch or VB Script : System inventory of PC

Hello experts,

I need to a VB Script or a bat file that do the following:

Write into a system-inventory.xls file (Generated at the same place in which the script is launch) of a computer (not a server)

Manufacturer
Serial number
OS (64 /32 bit)
Processor
C:\ Total (GB)
C:\ Avail (GB)
Memory Total (GB)
Memory Avail (GB)


There is an excellent code which retrieve all this information ID: 40648408, however I would like to launch the same script for the active computer without specifying the computer name or IP address.

Thank you in advance for your help.
LVL 1
LD16Asked:
Who is Participating?
 
RobSampsonCommented:
Sure, I have added (x86) or (x64) after the OS name.

If you want to add this to the other script, change
		' Get OS information
		Set colSystemInfo = objWMIService.ExecQuery("Select * from Win32_OperatingSystem",,48)
		For Each objItem in colSystemInfo
		     strOS_Caption = objItem.Caption
		     strOS_SPVersion = objItem.CSDVersion
		     strOS_VerNumber = objItem.Version
		     strOS_Memory = Trim(FormatNumber(objItem.TotalVisibleMemorySize/1024,0))
		Next

Open in new window


to this
		' Get OS information
		Set colSystemInfo = objWMIService.ExecQuery("Select * from Win32_OperatingSystem",,48)
		For Each objItem in colSystemInfo
		     intAddressWidth = objItem.OSArchitecture
		     If intAddressWidth = "32-bit" Then
		     	strOS_Caption = Trim(objItem.Caption) & " (x86)"
		     Else
		     	strOS_Caption = Trim(objItem.Caption) & " (x64)"
		     End If
		     strOS_SPVersion = objItem.CSDVersion
		     strOS_VerNumber = objItem.Version
		     strOS_Memory = Trim(FormatNumber(objItem.TotalVisibleMemorySize/1024,0))
		Next

Open in new window


Regards,

Rob.

Set objFSO = CreateObject("Scripting.FileSystemObject") 
Set objNetwork = CreateObject("WScript.Network")

arrComputers = Array(objNetwork.ComputerName)
strOutputFile = Replace(WScript.ScriptFullName, WScript.ScriptName, "") & "HardwareAudit.csv"

Set objOutput = objFSO.CreateTextFile(strOutputFile, True)
objOutput.WriteLine """Computername"",""IP Address"",""Manufacturer"",""Model"",""Serial Number"",""C:\ Total (GB)"",""C:\ Avail (GB)"",""Memory Total (GB)"",""Memory Avail (GB)"",""Processor"",""Operating System"",""OS Version"",""Service Pack"""

For Each strComputer In arrComputers
	' Create the WMI session
	If Ping(strComputer) = True Then
		Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
		
		' Get computername, manufacturer, and model
		Set colComputer = objWMIService.ExecQuery("Select * from Win32_ComputerSystem",,48)
		For Each objComputer in colComputer
		    strHostName = objComputer.Name
		    strManufacturer = objComputer.Manufacturer
		    strModel = objComputer.Model
		Next
		
		'Get IP Address
		Set colComputerIP = objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration",,48)
		strIPAddress = ""
		For Each IPConfig in colComputerIP
			If Not IsNull(IPConfig.IPAddress) Then 
				'strIPAddress = strIPAddress & IPConfig.Description & ": "
		        For intIPCount = LBound(IPConfig.IPAddress) To UBound(IPConfig.IPAddress)
		        	If IPConfig.IPAddress(intIPCount) <> "0.0.0.0" And InStr(IPConfig.IPAddress(intIPCount), ".") > 0 Then
						If strIPAddress = "" Then
							strIPAddress = IPConfig.IPAddress(intIPCount)
						Else
							strIPAddress = strIPAddress & ";" & IPConfig.IPAddress(intIPCount)
						End If
					End If
				Next
			End If
		Next
	
		' Get the serial number
		Set colItems = objWMIService.ExecQuery("Select * from Win32_BIOS",,48)
		For Each objItem In colItems
			strSerialNumber = Trim(objItem.SerialNumber)
		Next
		
		' Get OS information
		Set colSystemInfo = objWMIService.ExecQuery("Select * from Win32_OperatingSystem",,48)
		For Each objItem in colSystemInfo
		     intAddressWidth = objItem.OSArchitecture
		     If intAddressWidth = "32-bit" Then
		     	strOS_Caption = Trim(objItem.Caption) & " (x86)"
		     Else
		     	strOS_Caption = Trim(objItem.Caption) & " (x64)"
		     End If
		     strOS_SPVersion = objItem.CSDVersion
		     strOS_VerNumber = objItem.Version
		     strOS_Memory = Trim(FormatNumber(objItem.TotalVisibleMemorySize/1024,0))
		Next
	
		' Get available memory
		Set colItems = objWMIService.ExecQuery("Select * from Win32_PerfFormattedData_PerfOS_Memory",,48)
		For Each objItem in colItems
			strAvailableMemory = Trim(Round(objItem.AvailableBytes / (1024 *1024 * 1024),2))
		Next
		
		' Get CPU Details
		Set colItems = objWMIService.ExecQuery("Select * from Win32_Processor",,48)
		strCPUDetails = ""
		For Each objItem In colItems
			If strCPUDetails = "" Then
				strCPUDetails = Trim(objItem.Name)
			Else
				strCPUDetails = strCPUDeatils & ";" & Trim(objItem.Name)
			End If
		Next
	
		' Get Hard Drive Size
		Dim strDiskSizes
		Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
		Set colItems = objWMIService.ExecQuery("Select * from Win32_LogicalDisk Where DriveType = 3 And Name='C:'")
		For Each objItem In colItems
		   	strDiskSize = Trim(Round(objItem.Size / 1024 / 1024 / 1024, 2))
		   	strDiskFreeSpace = Trim(Round(objItem.FreeSpace / 1024 / 1024 / 1024, 2))
		Next
		
		objOutput.WriteLine """" & strHostName & """,""" & strIPAddress & """,""" & strManufacturer & """,""" & strModel & """,""" & strSerialNumber & """,""" & strDiskSize & """,""" & strDiskFreeSpace & """,""" & strOS_Memory & """,""" & strAvailableMemory & """,""" & strCPUDetails & """,""" & strOS_Caption & """,""" & strOS_VerNumber & """,""" & strOS_SPVersion & """"
	End If
Next

objOutput.Close
Set objOutput = Nothing
WScript.Echo "Done. Please see " & strOutputFile

Function Ping(strComputer)
	Dim objShell, boolCode
	Set objShell = CreateObject("WScript.Shell")
	boolCode = objShell.Run("Ping -n 1 -w 300 " & strComputer, 0, True)
	If boolCode = 0 Then
		Ping = True
	Else
		Ping = False
	End If
End Function

Open in new window

0
 
RobSampsonCommented:
Hi, taking that solution as a base, it's just a matter of modifying the array to include the local computer, and it generates the same CSV file.

Regards,

Rob.

Set objFSO = CreateObject("Scripting.FileSystemObject") 
Set objNetwork = CreateObject("WScript.Network")

arrComputers = Array(objNetwork.ComputerName)
strOutputFile = Replace(WScript.ScriptFullName, WScript.ScriptName, "") & "HardwareAudit.csv"

Set objOutput = objFSO.CreateTextFile(strOutputFile, True)
objOutput.WriteLine """Computername"",""IP Address"",""Manufacturer"",""Model"",""Serial Number"",""C:\ Total (GB)"",""C:\ Avail (GB)"",""Memory Total (GB)"",""Memory Avail (GB)"",""Processor"",""Operating System"",""OS Version"",""Service Pack"""

For Each strComputer In arrComputers
	' Create the WMI session
	If Ping(strComputer) = True Then
		Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
		
		' Get computername, manufacturer, and model
		Set colComputer = objWMIService.ExecQuery("Select * from Win32_ComputerSystem",,48)
		For Each objComputer in colComputer
		    strHostName = objComputer.Name
		    strManufacturer = objComputer.Manufacturer
		    strModel = objComputer.Model
		Next
		
		'Get IP Address
		Set colComputerIP = objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration",,48)
		strIPAddress = ""
		For Each IPConfig in colComputerIP
			If Not IsNull(IPConfig.IPAddress) Then 
				'strIPAddress = strIPAddress & IPConfig.Description & ": "
		        For intIPCount = LBound(IPConfig.IPAddress) To UBound(IPConfig.IPAddress)
		        	If IPConfig.IPAddress(intIPCount) <> "0.0.0.0" And InStr(IPConfig.IPAddress(intIPCount), ".") > 0 Then
						If strIPAddress = "" Then
							strIPAddress = IPConfig.IPAddress(intIPCount)
						Else
							strIPAddress = strIPAddress & ";" & IPConfig.IPAddress(intIPCount)
						End If
					End If
				Next
			End If
		Next
	
		' Get the serial number
		Set colItems = objWMIService.ExecQuery("Select * from Win32_BIOS",,48)
		For Each objItem In colItems
			strSerialNumber = Trim(objItem.SerialNumber)
		Next
		
		' Get OS information
		Set colSystemInfo = objWMIService.ExecQuery("Select * from Win32_OperatingSystem",,48)
		For Each objItem in colSystemInfo
		     strOS_Caption = objItem.Caption
		     strOS_SPVersion = objItem.CSDVersion
		     strOS_VerNumber = objItem.Version
		     strOS_Memory = Trim(FormatNumber(objItem.TotalVisibleMemorySize/1024,0))
		Next
	
		' Get available memory
		Set colItems = objWMIService.ExecQuery("Select * from Win32_PerfFormattedData_PerfOS_Memory",,48)
		For Each objItem in colItems
			strAvailableMemory = Trim(Round(objItem.AvailableBytes / (1024 *1024 * 1024),2))
		Next
		
		' Get CPU Details
		Set colItems = objWMIService.ExecQuery("Select * from Win32_Processor",,48)
		strCPUDetails = ""
		For Each objItem In colItems
			If strCPUDetails = "" Then
				strCPUDetails = Trim(objItem.Name)
			Else
				strCPUDetails = strCPUDeatils & ";" & Trim(objItem.Name)
			End If
		Next
	
		' Get Hard Drive Size
		Dim strDiskSizes
		Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
		Set colItems = objWMIService.ExecQuery("Select * from Win32_LogicalDisk Where DriveType = 3 And Name='C:'")
		For Each objItem In colItems
		   	strDiskSize = Trim(Round(objItem.Size / 1024 / 1024 / 1024, 2))
		   	strDiskFreeSpace = Trim(Round(objItem.FreeSpace / 1024 / 1024 / 1024, 2))
		Next
		
		objOutput.WriteLine """" & strHostName & """,""" & strIPAddress & """,""" & strManufacturer & """,""" & strModel & """,""" & strSerialNumber & """,""" & strDiskSize & """,""" & strDiskFreeSpace & """,""" & strOS_Memory & """,""" & strAvailableMemory & """,""" & strCPUDetails & """,""" & strOS_Caption & """,""" & strOS_VerNumber & """,""" & strOS_SPVersion & """"
	End If
Next

objOutput.Close
Set objOutput = Nothing
WScript.Echo "Done. Please see " & strOutputFile

Function Ping(strComputer)
	Dim objShell, boolCode
	Set objShell = CreateObject("WScript.Shell")
	boolCode = objShell.Run("Ping -n 1 -w 300 " & strComputer, 0, True)
	If boolCode = 0 Then
		Ping = True
	Else
		Ping = False
	End If
End Function

Open in new window

0
 
LD16Author Commented:
Excellent, Is it possible to add the 32 or 64 bits OS ?
Thank you in advance for your help.
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

 
LD16Author Commented:
Excellent! Thank you again Rob!
0
 
LD16Author Commented:
Excellent!
0
 
RobSampsonCommented:
No problem.

Rob.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.