SideBar    How the Inventory Agent Works, How the Report Agent Works
DOWNLOAD THE CODE:
Download the Code 39111.zip

Analyzing the Data
After inventory collection is complete, you can review individual inventory files in Notepad. Each text file contains sections, such as ComputerSystem and IDEController, that represent a characteristic of the inventoried computer. Not every inventory file contains every section, however. For example, if you inventory a computer that contains a SCSI controller but no IDE controller, the corresponding file will contain a SCSIController section but won't contain an IDEController section.

Also, a system's OS version will affect the amount of hardware that the inventory file displays. For example, a Win98 system's inventory file won't contain a PhysicalMedia section because the Win32_PhysicalMedia WMI class is available only on Windows 2003 or XP machines.

Within the available sections, you might notice some items with values listed as Not available. This value occurs when a hardware manufacturer hasn't stored data for a particular WMI property or when WMI can't locate a property's value.

The inventory analysis demonstrates that a computer's OS and hardware components, as well as the properties of each hardware device, create exceptions to uniform inventory collection across all computers. Still, the script will leave you with a rich collection of useful inventory information.

Building the Report
Telling members of the Accounting team that they can go to your hardware-collection directory to view 5000 tiny text files containing the information they want probably won't sit too well with your boss. The next step, then, is to create a hardware inventory report. Enter our trusty report agent, BuildReport.vbs. The report agent reads each file, locates sections of inventory data, then writes the data to individual worksheets in an Excel workbook named InvReport.xls. (For details about how the script works, see the sidebar "How the Report Agent Works," page 4.)

Excel is a good choice for consolidating the inventory data for several reasons. First, Excel is widely available. Second, the application lets you easily create rich reports and analyze collected data. And third, most people who work with inventory reports are familiar with Excel spreadsheet operation and analysis.

Before running the report agent, you must make two minor changes to lines 9 and 10 of BuildReport.vbs. Line 9 contains the strInvFilePath variable and specifies the path to the hardware-collection directory; Line 10 contains the strReportPath variable and specifies the location in which you want the script to create InvReport.xls. Change these values to suit your environment.

Before you run BuildReport.vbs, you need to know three details about the report agent. First, the agent relies on the Excel application object. Therefore, make sure that Excel is installed on the computer on which you'll run the agent.

Second, I intentionally wrote the agent to display a processing message as it parses each inventory file; this regular output assures you that the script is successfully processing the inventory files. (When I ran the agent on a 1GHz Pentium III computer with 512MB of memory, each file required approximately 3 seconds to process.) Because of this output, you must use WSH's CScript host engine to run the script so that the script will continue after it processes each record. If you were to use WSH's WScript host engine, you'd need to click OK each time—a lot of clicking if you have 10,000 inventory files to process. To run the report agent with CScript, either make CScript your default host or open a command prompt, go to the directory that contains the report agent, and type

cscript buildreport.vbs

Third, consider the time the report agent will take to run before you begin the process. If each file takes 3 seconds to process and you have 10,000 files, complete report generation will require 30,000 seconds, or 8.3 hours. Therefore, consider running the report at night and on a fast computer that isn't busy completing other tasks.

Figure 1 shows an example of the output you'll see when the report agent finishes its work. (To show as much data as possible in this figure, I've hidden toolbars and reduced cell width.) The figure shows the Computer Systems worksheet; the workbook includes 14 worksheets in all, one for each section of inventory data: Computer Systems, Page Files, RAM, SCSI Controllers, IDE Controllers, Disk SerNums, Removable Media, Fixed Disks, Processors, NICs, Monitors, Video Adapters, Motherboards, and BIOS. You can modify the inventory agent and report agent scripts to collect more data from each computer if you want.

Inventory in a Nutshell
You now have a lightweight yet verbose inventory-collection and -reporting tool—and for nothing more than a subscription to this newsletter. I hope you, your boss, and the accounting department will all be thrilled.

End of Article

Prev. page     1 [2]     next page -->



You must log on before posting a comment.

If you don't have a username & password, please register now.

Reader Comments

<P>Great article but since the most important part in an inventory is the serial number, is there a way to get the serial number of the PC?<B>--Don</B></P> <P>If you want the serial number look at the IdentifyingNumber property of Win32_ComputerSystemProduct. Works on most computers built since 2001. Older computers may or may not report their serial number.<B>--Bill Schalck, April 19, 2004</B></P>

Don

<P>Great code and just when I needed it!</P>

Martin

<P>When I run the inventory script against my PC, I get this error, which occurs after OSInformation, ComputerSystem, PageFileSetting, and PhysicalMemoryArray have been recorded in the .txt file:</P> <BR> ---------------------------<BR> Windows Script Host<BR> ---------------------------<BR> Script: C:\Documents and <BR> Settings\JeffV\Desktop\Hardware<BR> Inventory\HrdWrInv.vbs<BR> Line: 154<BR> Char: 3<BR> Error: 0x80041001<BR> Code: 80041001<BR> Source: (null)<BR> <BR> ---------------------------<BR> OK<BR> ---------------------------<BR> <BR> <P>The line that errors out is this one in the QueryInstances subroutine:<BR> <BR> <DD>For Each objComponent in objClassName</P>

Jeff

Hi! Just wanted to make a small remark concerning the code:

<P>First HrdWrInv.vbs, line 93 reads:<BR> <BR> If Mid(intVersion,1,3) >= 5.1 Then<BR> <BR> This should read:<BR> <BR> If Mid(intVersion,1,3) >= "5.1" Then<BR> <BR> or the script would not run on my WinXPPro.</P>

<P>Second, in BuildReport.vbs, line 295 reads:<BR> <BR> RenameSheets "Sheet" & i,WBName<BR> <BR> My Norwegian Office calls these sheets "Ark", and this script didn't run either, until I corrected this.</P>

Thomas Hansen

<P>This was very helpful in a bind. Code works well. Easy to read and modify!</P>

Scott

<P>I really enjoyed this article about the hardware inventory. It will probably get lots of use here. I have been looking for this exact code. We've been using a third-party software package for this, but since we've upgraded our security, that package no longer works.</P> <P>I do have a few questions, though: What code should I put in if I want to collect the username on the Computer Systems tab in the Excel report? What needs to go in the hardware script AND what should I put in the report generator?</P>

<P><B>A note from Ethan: </B>The Computer Systems tab is populated with information from the Win32_ComputerSystem class. In this class, there are two additional properties that will probably provide you with what you're looking for: UserName and PrimaryOwnerName.</P>

<P>In hrdwrInv.vbs, you need to add these two properties to the strProperties variable for Win32_ComputerSystem. You'll see the properties listed on lines 64 - 66. In buildReport.vbs, you need to add column heads for the two new properties. The column heads are specified for Win32_ComputerSystem on lines 49 and 50.</P>

Carl Klima

This is going to work well for us. I modified a bit to get the UserName and SerialNumber. Now just to make it automatically run on all computers on the domain......

Craig

<P>I was trying to get the SerialNumber property from the bios and entered the property in Line 133 in HrdWrInv.vbs and added the property on line 97 of the buildReport.vbs. The info is collected in the text file but doesn't show up in the Excel report. Did i omit something?</P>

Jean-Claude

<P>This is great. I have been reading up on the WMI classes and was trying to pull the network settings (ipaddress/DNS/GW, etc) but it always gives me errors. Any thoughts? I would also like to grab some software info. Is there an easy class that has the SW listed in ADD/remove only? What about hotfix/updates? Thanks for the great script!</P>

Bill Prochazka

On Windows 2000 Pro i have got thi error: --------------------------- Windows Script Host --------------------------- Script: C:\Documents and Settings\Tommaso\Desktop\HrdWrInv.vbs Line: 154 Char: 3 Error: 0x80041001 Code: 80041001 Source: (null)

--------------------------- OK ---------------------------

I have already try to update to version 5.6 of scipt engine but i have got it again. What i can do to solve the problem

Tommaso

Great article/script. Straightforward and works great - unlike most resources out there! Ran into the same exact scenario with my accounting department and got all 130 servers and workstations inventoried in 2 days through Group Policy. Thanks for the help.

Rob Wurster

This is most useful. I was able to run the inventory script without error but when I ran the report script the processing inventory box appears but as soon as I press OK I get a script error. Line: 36, Char: 5, Error: File not found, Code: 800a0035. Line 36 only contains comments???

nbk24o8

Article Rating 5 out of 5

Works great, BUT anyone know how to detect the Serial Numbers of disk drives in a RAID? This program detects, "MEGA RAID 5" not enough info!

racer999

Article Rating 4 out of 5

Hi all, When i try to execute the script to colect data about windows 98 machine, this error apears:

The remote server does not exists.... Cod: 800A01CE

PS: Windows2k is ok.

Anonymous User

Not to sound LAZY, but its been a while since I've done any programming and thought I'd ask..even though I am being lazy.

Can someone email me the script with the changes that will collect the username and password?

joe.oldendick@gmail.com

Thanks!

JoeOldendick

See More Comments  1   2 
 
 

ADS BY GOOGLE