Get SerialNumber via Script

Posted on 2004-08-31
Last Modified: 2010-04-17
Hi experts,
i have a problem with my script, which reads out the SerialNumber of my PCs,
but i doesn't work on Serverhardware (the most are DELL PowerEdge 2550 and 2650).
Here is  the script:

dim fso, txtfile, serversfile
dim server, strSN

set fso = CreateObject("Scripting.FileSystemObject")
set txtfile = fso.CreateTextFile("C:\serialnumbers.txt")
set serverfile = fso.OpenTextFile("C:\servers.txt")

do while not serverfile.AtEndOfStream
      server = serverfile.ReadLine
      set BIOSSet = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &server & "\root\cimv2").ExecQuery("select SerialNumber from Win32_BIOS")
      for each BIOS in BIOSSet
            strSN = BIOS.SerialNumber
            txtfile.writeline  server &"   " &strSN

Question by:merowinger

Accepted Solution

rsriprac earned 250 total points
Comment Utility
This requires the WMI API (


$serv_tag = WMIQuery("SerialNumber","Win32_SystemEnclosure","winmgmts","\root\cimv2")
If InStr($serv_tag," ")
   $serv_tag = WMIQuery("SmBiosAssetTag","Win32_SystemEnclosure","winmgmts","\root\cimv2")
Function WMIQuery($what,$from,$type,$namespace, optional $computer,optional $where, optional $x)
   Dim $strQuery, $objEnumerator, $value, $item
   If NOT $computer $computer="@WKSTA" EndIf
   $strQuery = "Select $what From $from"
   If $where AND $x $strQuery = $strQuery + " Where $where = '$x'" EndIf
   $SystemSet = GetObject($type + ":{impersonationLevel=impersonate}!//$computer"+ $namespace)
   If @error Exit 1 Return EndIf
   $objEnumerator = $SystemSet.ExecQuery($strQuery)
   For Each $objInstance in $objEnumerator
      If @Error = 0 AND $objInstance <> ""
         $=Execute("$$value = $$objInstance.$what")
         Case VarType($value) = 8204
            For Each $item in $value $WMIQuery = "$item" +"|"+"$WMIQuery" Next
         Case VarType($value) = 8 $WMIQuery = "$value"+"|"+"$WMIQuery"
         Case VarType($value) = 3 $WMIQuery = "$value"+"|"+"$WMIQuery"
         Case 1 $WMIQuery = "Unhandled data type returned: " + VarTypeName($value) + "(" + VarType($value) + ")"
   Exit @error


Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Fix45 challenge 15 83
Using YubiKey with REST API application 2 77
strCount chalenge 3 50
C Programming - If Statement 8 47
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

763 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

14 Experts available now in Live!

Get 1:1 Help Now