Get SerialNumber via Script

Posted on 2004-08-31
Medium Priority
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
1 Comment

Accepted Solution

rsriprac earned 1000 total points
ID: 11941241
This requires the WMI API (http://0url.com/4t)


$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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
If you are a mobile app developer and especially develop hybrid mobile apps then these 4 mistakes you must avoid for hybrid app development to be the more genuine app developer.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

850 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