?
Solved

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

Posted on 2006-05-22
5
Medium Priority
?
459 Views
Last Modified: 2008-01-16
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 or some other 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
sSystem=Wscript.Arguments(0)
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
Next
0
Comment
Question by:mystikal1000
  • 4
5 Comments
 
LVL 33

Expert Comment

by:NJComputerNetworks
ID: 16735086
You can use an array...for example:


Computers = array("server1", "server2", "server3")


For each Computer in Computers
   on error resume Next
   Set objWMIService = GetObject("winmgmts://" & Computer & "\root\cimv2")
   Set colAdapters = objWMIService.ExecQuery ("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
   
   n = 1

        For Each objAdapter in colAdapters

            WScript.Echo objAdapter.DNSHostName & "," & objAdapter.WINSPrimaryServer & "," & objAdapter.WINSSecondaryServer
              n = n + 1
      Next

Next
0
 
LVL 33

Accepted Solution

by:
NJComputerNetworks earned 1500 total points
ID: 16735100
Or an example of using a text file:

Const ForReading = 1
Set objDictionary = CreateObject("Scripting.Dictionary")
Set objFSO = CreateObject("Scripting.FilesystemObject")
Set ObjtextFile = objFSO.Opentextfile("Y:\vbscripts\WindowsScripts\Joe_test\serverlist.txt", ForReading)

i = 0
Do Until objtextfile.AtEndOfStream
      strnextline=objtextfile.readline
      objdictionary.add i, strnextline
      i=i+1
loop

For each objitem in objdictionary
   Strcomputer = objdictionary.item(objitem)
      wscript.echo strcomputer      
   Set objWMIService = GetObject("winmgmts:" & "{impersonationlevel=impersonate}!\\"  & strcomputer& "\root\cimv2")
   Set colAdapters = objWMIService.ExecQuery ("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
   
   n = 1

        For Each objAdapter in colAdapters

            strOutput = strOutput & strComputer & ","

If Not IsNull(objAdapter.IPAddress) Then
For i = 0 To UBound(objAdapter.IPAddress)
strOutput = strOutput & objAdapter.IPAddress(i)
If i <> UBound(objAdapter.IPAddress) Then
strOutput = strOutput & " "
Else
strOutput = strOutput & ","
End If
Next
End If

strOutput = strOutput & objAdapter.MACAddress & ","
strOutput = strOutput & objAdapter.WINSPrimaryServer & ","
strOutput = strOutput & objAdapter.WINSSecondaryServer & ","

If Not IsNull(objAdapter.DNSServerSearchOrder) Then
For i = 0 To UBound(objAdapter.DNSServerSearchOrder)
strOutput = strOutput & objAdapter.DNSServerSearchOrder(i) & ","
Next
End If

If Not IsNull(objAdapter.DNSDomainSuffixSearchOrder) Then
For i = 0 To UBound(objAdapter.DNSDomainSuffixSearchOrder)
strOutput = strOutput & objAdapter.DNSDomainSuffixSearchOrder(i) & ","
Next
End If

strOutput = strOutput & objAdapter.Description & ","

objOutputFile.Writeline strOutput
strOutput = "Y:\vbscripts\WindowsScripts\Joe_test\output.txt"

n = n + 1

Set objAdapter = Null
Set colAdapters = Null
objAdapter = Nothing
colAdapters = Nothing

Next



Next

0
 
LVL 1

Author Comment

by:mystikal1000
ID: 16736570
Does this find the serial numbers or model numbers on the servers or network adapters?
0
 
LVL 33

Expert Comment

by:NJComputerNetworks
ID: 16736631
no... this is an example of how to use a TEXT file in a vbscript... or how to enter mulitple server names inside the script.
0
 
LVL 33

Expert Comment

by:NJComputerNetworks
ID: 16736827

Computers = array("server1","server2","server3")


For each Computer in Computers
On Error Resume Next

Set objWMIService = GetObject("winmgmts:\\" & computer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_BIOS",,48)
For Each objItem in colItems
    Wscript.Echo "BiosCharacteristics: " & objItem.BiosCharacteristics
    Wscript.Echo "BIOSVersion: " & objItem.BIOSVersion
    Wscript.Echo "BuildNumber: " & objItem.BuildNumber
    Wscript.Echo "Caption: " & objItem.Caption
    Wscript.Echo "CodeSet: " & objItem.CodeSet
    Wscript.Echo "CurrentLanguage: " & objItem.CurrentLanguage
    Wscript.Echo "Description: " & objItem.Description
    Wscript.Echo "IdentificationCode: " & objItem.IdentificationCode
    Wscript.Echo "InstallableLanguages: " & objItem.InstallableLanguages
    Wscript.Echo "InstallDate: " & objItem.InstallDate
    Wscript.Echo "LanguageEdition: " & objItem.LanguageEdition
    Wscript.Echo "ListOfLanguages: " & objItem.ListOfLanguages
    Wscript.Echo "Manufacturer: " & objItem.Manufacturer
    Wscript.Echo "Name: " & objItem.Name
    Wscript.Echo "OtherTargetOS: " & objItem.OtherTargetOS
    Wscript.Echo "PrimaryBIOS: " & objItem.PrimaryBIOS
    Wscript.Echo "ReleaseDate: " & objItem.ReleaseDate
    Wscript.Echo "SerialNumber: " & objItem.SerialNumber
    Wscript.Echo "SMBIOSBIOSVersion: " & objItem.SMBIOSBIOSVersion
    Wscript.Echo "SMBIOSMajorVersion: " & objItem.SMBIOSMajorVersion
    Wscript.Echo "SMBIOSMinorVersion: " & objItem.SMBIOSMinorVersion
    Wscript.Echo "SMBIOSPresent: " & objItem.SMBIOSPresent
    Wscript.Echo "SoftwareElementID: " & objItem.SoftwareElementID
    Wscript.Echo "SoftwareElementState: " & objItem.SoftwareElementState
    Wscript.Echo "Status: " & objItem.Status
    Wscript.Echo "TargetOperatingSystem: " & objItem.TargetOperatingSystem
    Wscript.Echo "Version: " & objItem.Version
    Wscript.Echo
    Wscript.Echo
Next
nEXT
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've always wanted to allow a user to have a printer no matter where they login. The steps below will show you how to achieve just that. In this Article I'll show how to deploy printers automatically with group policy and then using security fil…
ADCs have gained traction within the last decade, largely due to increased demand for legacy load balancing appliances to handle more advanced application delivery requirements and improve application performance.
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …

839 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