• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 167
  • Last Modified:

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

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
1 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
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.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now