This is another useful script I sometimes use when I need to collect some basic inventory data from a list of machines. The attached vbscript takes an input file called workstations.txt and produces an comma separated output file called workstationinventory.txt. You can modify the two constants at the top of the file as noted below if you want to change this:
The script currently only outputs a limited set of information but the framework is there to extend it to collect really anything available via WMI. The fields currently exported are:
- Make
- Model
- BIOS Version
- Operation System
- Serial Number
To configure the input and output file modify lines 12 and 13:
Const PATH_TO_INPUT = "workstations.txt"
Const PATH_TO_OUTPUT = "workstationinventory.txt"
If you're looking for some guidance on other WMI data, check out the Scriptomatic tool from Microsoft.
The script is attached below in a zip. If you have any comments, bugs, etc feel free to leave them in the comments field and I'll take a look.
UPDATE: Script download link - http://www.briandesmond.com/blog-attachments/collectworkstationinventory.zip
Comments, Trackbacks, & Pingbacks
#1 re: Script to Collect Basic Inventory Data From Machines
Monday, April 30 2007 3:37 PM by Nick#2 re: Script to Collect Basic Inventory Data From Machines
Monday, June 25 2007 9:59 AM by L PI tested your script and for some reason I am getting duplicate data, perhaps for machines that don't respond to wmi.
#3 re: Script to Collect Basic Inventory Data From Machines
Sunday, August 26 2007 1:24 AM by JeremyGreat script Brian, thanks! I've modified it to add a few more wmi features. I've also set it to open up as an Excel spread sheet, formatted into four work sheets. Here's the new code in case you're interested.
'==========================================================================
' NAME: Script to Collect Inventory Information
'
' AUTHOR: Brian Desmond
' DATE : 10/22/2006
'
' MODIFIED: Jeremy Schubert
' DATE: 25/07/2007
'
'==========================================================================
Option Explicit
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
Const PATH_TO_INPUT = "g:\scripts\studentworkstations.txt"
Const PATH_TO_OUTPUT = "g:\scripts\Grandin (047) Student Computer Inventory.csv"
Dim fso
Set fso = WScript.CreateObject("Scripting.FileSystemObject")
Dim shl
Set shl = WScript.CreateObject("WScript.Shell")
Dim input
Set input = fso.OpenTextFile(PATH_TO_INPUT)
Dim output
Set output = fso.CreateTextFile(PATH_TO_OUTPUT, True)
output.WriteLine "Hostname,Description,Serial Number,Make,Model,IP Address,MAC,RAM,Processor,Hard Drive Size,BIOS Version,Operating System,Service Pack"
Dim wmiService
Dim wmiResults
Dim hostname
Dim make
Dim model
Dim biosversion
Dim operatingSystem
Dim descriptio
Dim serialNumber
Dim description
Dim harddrivesize
Dim processor
Dim ram
Dim macaddress
Dim ipaddress
Dim servicepack
Dim line
Dim exec
Dim pingResults
While Not input.AtEndOfStream
line = input.ReadLine
hostname = ""
make = ""
model = ""
biosversion = ""
operatingSystem = ""
serialNumber = ""
description = "."
harddrivesize = ","
ram = ","
ipaddress = "."
macaddress = "."
servicepack = "."
Set exec = shl.Exec("ping -n 2 -w 1000 " & line)
pingResults = LCase(exec.StdOut.ReadAll)
If InStr(pingResults, "reply from") Then
WScript.Echo "Reply From: " & line
'On Error Resume Next
Set wmiService = GetObject("winmgmts:\\" & line & "\root\CIMV2")
Set wmiResults = wmiService.ExecQuery("SELECT * FROM Win32_BIOS", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly)
Dim item
For Each item In wmiResults
hostname = line
serialNumber = item.SerialNumber
biosversion = item.SMBIOSBIOSVersion
Next
Set wmiService = GetObject("winmgmts:\\" & line & "\root\CIMV2")
Set wmiResults = wmiService.ExecQuery("SELECT * FROM Win32_ComputerSystem", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly)
For Each item In wmiResults
make = item.Manufacturer
model = item.Model
ram = item.TotalPhysicalMemory
Next
Set wmiService = GetObject("winmgmts:\\" & line & "\root\CIMV2")
Set wmiResults = wmiService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly)
For Each item
#4 re: Script to Collect Basic Inventory Data From Machines
Monday, August 11 2008 12:16 PM by RobertIs there a way to specify a userid and pwd to connect with to pull the information? I am able to collect information for localhost but not remote machines.



Brian, I coded something similar to your basic inventory script for small-to-midsized organizations. Instead of using a text file with computer names, it queries AD and grabs computer objects. I have a bunch of stuff that get's inventoried, and used Scriptomatic to track down where stuff lives. Thought you and your readers might find it interesting.
http://addicted-to-it.blogspot.com/2007/01/ad-coit-v23-inventory-tool-released-on.html