How do I get system serial number using VB script for list of servers.

Posted on 2006-05-25
Last Modified: 2008-02-01
I am looking for a quick way to collect serial numbers from Windows 2000 and greater servers using an external host file.

I have a text file that has server names in it. I want to either run a VBS command that will read the text host file, query the server then output to another file the servers name, serial number, model number, then go to the next one until the end of the file.

Also, if it doesn't find the server then put in the words "not online" instead of a serial number.

I have this script that will retrieve the serial number one at a time, but would like something I described above?

On Error Resume Next
Dim System
if Wscript.Arguments.Count >0 then
end if
ComputerName = InputBox("Enter the name of the computer you wish to query")
winmgmt1 = "winmgmts:{impersonationLevel=impersonate}!//"& ComputerName &""
Set SNSet = GetObject( winmgmt1 ).InstancesOf ("Win32_BIOS")
for each SN in SNSet
MsgBox "The serial number for the specified computer is: " & SN.SerialNumber
Question by:mystikal1000
    1 Comment
    LVL 23

    Accepted Solution

    Code below - change COMPUTER_NAMES_FILE to the file that contains all the computer names.  You didn't specify, so I have assumed a file containing one computername per line, like this:


    Change RESULTS_FILE to the location where you want the results output.  The results file will be overwritten each time the script runs.

    const FSO_READ_MODE = 1
    const FSO_WRITE_MODE = 2
    const COMPUTER_NAMES_FILE = "C:\servers.txt"
    const RESULTS_FILE = "C:\results.txt" 'warning - will be overwritten each time script runs

    Dim fso: Set fso = CreateObject("Scripting.FileSystemObject")

    Set fso = Nothing

    function CheckSerial(ComputerName)
          Dim System
          Dim retVal
          if Wscript.Arguments.Count > 0 then
          end if
          winmgmt1 = "winmgmts:{impersonationLevel=impersonate}!//"& ComputerName &""
          Set SNSet = GetObject( winmgmt1 ).InstancesOf ("Win32_BIOS")
          for each SN in SNSet
                retVal = retVal & "The serial number for " & ComputerName & " is: " & SN.SerialNumber
          CheckSerial = retVal
    end function

    function ReadFile(sFilePath)
          If fso.FileExists(sFilePath) then
                'The file exists, so open it and output its contents
                dim file: set file = fso.OpenTextFile(sFilePath, FSO_READ_MODE)
                dim sLine
                dim sResults: sResults = ""
                Do While file.AtEndOfStream = False
                    sLine = file.ReadLine
                    sResults = sResults & CheckSerial(sLine) & vbcrlf
                Set file = Nothing
                WriteResults sResults
                'The file did not exist
                msgbox sFilePath & " was not found."
          End If
    end function

    sub WriteResults(sResults)
          dim file: set file = fso.OpenTextFile(RESULTS_FILE, FSO_WRITE_MODE, true)
          Set file = Nothing
    end sub

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
    Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
    Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now