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
ID: 11941241
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
allStar challenge 1 52
Image decoding from Camera 3 72
Windows and other UI names - The Proper names for the Various elements! 1 58
iSeries email authority 4 20
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.
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
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…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

911 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

18 Experts available now in Live!

Get 1:1 Help Now