Subscribe to Windows IT Pro
June 09, 2003 12:00 AM

Home-Brewed Hardware Inventory

Create a full-bodied hardware inventory report from just a few simple ingredients
Windows IT Pro
InstantDoc ID #39111
Rating: (15)
Downloads
39111.zip

Your boss calls you and says, "Accounting needs a hardware inventory report by the end of the week. Oh, and don't even think about spending money on an inventory software package." What started out as a pleasant day has taken a turn for the worse.

You can manually inventory every computer in your company, you can quit your job, you can claim that the task can't be done—or you can use a two-pronged scripting solution that collects hardware inventory and generates a Microsoft Excel report in record time. This solution—which requires only Windows Management Instrumentation (WMI), Windows Script Host (WSH) 5.6, and Excel 2000 or later—can gather extensive inventory data from Windows Server 2003, Windows XP, Windows 2000, Windows NT 4.0 (Service Pack 4—SP4—or later), Windows Me, and Windows 98 systems.

Preparing for the Inventory
The hardware inventory solution consists of two scripts. The first script, HrdWrInv.vbs, is an inventory agent that collects hardware information from each computer on the network. The second script, BuildReport.vbs, is a report agent that creates an Excel workbook containing hardware inventory data from all the computers on which HrdWrInv.vbs ran successfully. You can download both scripts from http://www.winscriptingsolutions.com, InstantDoc ID 39111.

When the inventory agent runs on a system, the script creates a small text file, typically no larger than 6KB, and names the file HrdWrInv_ComputerName.txt (where ComputerName is the name of the inventoried computer). HrdWrInv.vbs places each file in a directory—which I refer to as the hardware-collection directory—that you specify for the strInvFilePath variable, which appears on line 22 of the script. Make sure that you specify a network path that all users who run the inventory agent can access, and follow the path with a backslash (\). Also, give users Read and Write access to the hardware-collection directory. The default path that I use in HrdWrInv.vbs is \\sea-fs-02\hw\, which points to the hw share on a file server named sea-fs-02; you'll need to replace this path with one suitable to your environment.

You can use a drive letter to specify the path (e.g., G:\inventory\hw), but if you do so, each user needs to map the drive letter to the same network location so that the script will store all the inventory files in the same place. If you specify a Universal Naming Convention (UNC) path, you won't need to worry about whether all users have mapped the drive correctly.

The inventory agent relies on WMI and WSH 5.6. Windows 2003, XP, Win2K, and Windows Me systems install WMI by default; ensure that the WMI Core 1.5 components (which you can download at http://www.microsoft.com/downloads/details.aspx?familyid=afe41f46-e213-4cbf-9c5b-fbf236e0e875) are installed on any NT 4.0 SP4 or later or Win98 clients that will run the script. Windows 2003 and XP systems install WSH 5.6 by default; for Win2K, NT 4.0, Windows Me, and Win98 clients, you can download WSH 5.6 at http://msdn.microsoft.com/library/default.asp?url=/downloads/list/webdev.asp.

After you prepare the script and machines to run the inventory agent, you need to make the script available over the network. The script is silent and can be called as part of an existing logon-script processing routine. If you support only Win2K or later systems, you can call the agent as part of a Group Policy logon or logoff script-processing procedure. Alternatively, you could modify the inventory agent so that it remotely connects to WMI clients and collects inventory from a central location. To learn about techniques for making remote WMI connections, see "Remote Administration with WMI," February 2003, http://www.winscriptingsolutions.com, InstantDoc ID 37596.

You'll know the agent is doing its job when text files starting with the prefix HrdWrInv_ begin appearing in the hardware-collection directory. (For details about the agent, see the sidebar "How the Inventory Agent Works.") The next time the inventory agent runs on a computer, the agent will detect that it has already taken an inventory and the script will exit. If you want to inventory a computer again, simply delete that system's inventory file from the hardware-collection directory. The next time the agent runs, it will create a new inventory file.

Related Content:

ARTICLE TOOLS

Comments
  • Anne
    4 years ago
    Feb 25, 2008

    Dj, the code is still available to subscribers. Just click the blue Download the Code button at the top of the article to download the zip file w/ the code.

  • Darren
    4 years ago
    Feb 25, 2008

    This looks very useful but I suspect the code is no longer available due to age of article. If someone could help out id appreciate it.

  • Jeremy
    5 years ago
    Aug 20, 2007

    Great script Ethan. Does anyone check these comments anymore? I have a quick question. I've added two extra wmi categories to the inventory script. win32_operatingsystem and win32_computersystemproduct. I've been trying to figure out how to add another worksheet for each of those categories to the spreadsheet report. But I keep getting an Input Past End of File error, no matter what I do. Can someone please explain to me how I have to modify the BuildReport script to get it to add the two workstheers?

  • Anne
    5 years ago
    Aug 07, 2007

    drumgod007: To download the code, click the blue Download the Code Here button at the top of the article (just under the title information and links to the sidebars).

  • dj
    5 years ago
    Jul 31, 2007

    Where do i actually d/l the scripts from?? It says

    "You can download both scripts from http://www.winscriptingsolutions.com, InstantDoc ID 39111. . . . "

    Going there only leads to the article. I cannot find a location on the website to actually download the two scripts... can someone point me to the URL for both of them please...

You must log on before posting a comment.

Are you a new visitor? Register Here

advertisement

advertisement

Windows is a trademark of the Microsoft group of companies. Windows IT Pro is used by Penton Media Inc. under license from owner.