Solved

Get SerialNumber via Script

Posted on 2004-08-31
3
388 Views
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
      Next
Loop



thx
mero
0
Comment
Question by:merowinger
3 Comments
 
LVL 5

Accepted Solution

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

Code:

$serv_tag = WMIQuery("SerialNumber","Win32_SystemEnclosure","winmgmts","\root\cimv2")
If InStr($serv_tag," ")
   $serv_tag = WMIQuery("SmBiosAssetTag","Win32_SystemEnclosure","winmgmts","\root\cimv2")
EndIf
;****************************************************
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")
         Select
         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) + ")"
         EndSelect
      EndIf
   Next
   $WMIQuery=Left($WMIQuery,Len($WMIQuery)-1)
   Exit @error
EndFunction
;*****************************************************

0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
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…
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 …

830 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