Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Get SerialNumber via Script

Posted on 2004-08-31
3
Medium Priority
?
392 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 5

Accepted Solution

by:
rsriprac earned 1000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In this post we will learn different types of Android Layout and some basics of an Android App.
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
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 …
Progress

609 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