• 1. London, UK
  • 2. Sydney, Australia
  • 3. New York, NY
  • 4. Melbourne, Australia
  • 5. Bellevue, WA
  • 6. Paris, France
  • 7. Moscow, Russia
  • 8. Chicago, IL
  • 9. San Francisco, CA
  • 10. Amsterdam, Netherlands

Friday, April 15, 2005

 

Getting Dell Service Tag using WMI

Posted by Bharat Suneja at 10:35 AM
Need to maintain an accurate inventory of servers in datacenter. Dell servers have a Service Tag that is required when calling Dell support, and it makes sense to include this in the server list.

Here's how to retrieve the Service Tag from BIOS. This uses WMI, and therefore works on Windows servers only.

'Check for Arguments
If WScript.Arguments.Count = 0 Then
Wscript.Echo "Usage: GetDesllSvcTag.vbs computer1 [computer2] [computer3] ......"
WScript.Quit
End If

For Each strComputer In wscript.Arguments
Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colSMBIOS = objWMIService.ExecQuery _ ("Select * from Win32_SystemEnclosure")
For Each objSMBIOS in colSMBIOS
Wscript.Echo strComputer & ": " & objSMBIOS.SerialNumber
Next

Next

The production script I use queries AD (using ADSI) for all computers running Windows Server 2003/2000, gets their OS, Service Pack, and date of computer account creation, then connects to each server using the above method to get the Dell service tag (and other info, like number of CPUs, RAM, etc.).

To enable others to dynamically generate this list on demand, it is web-enabled and generates a better formatted web page with the required details (with ability to click on a server name and drill down to gather further info like IP config, drive utilization, etc.). The drill-down's required because a) You can't put everything in a list on the first page, it would be unreadable - endless scrolling 2) Would involve too many WMI calls to each server after initial AD query, and slow down the list generation to a crawl.

Labels:

12 Comments:

October 18, 2005 3:29 PM
Blogger Evans Tucker said...

Thank you VERY much for posting this script! I've been trying to find a way to get the service tags of all the machines on the network for a couple of hours now - this script is exactly what I was looking for!

 
June 23, 2006 4:24 AM
Anonymous Anonymous said...

Works for PCs as well as servers!

 
June 23, 2006 4:25 AM
Anonymous Anonymous said...

Works for PCs as well as servers!

 
February 1, 2007 3:46 PM
Anonymous Anonymous said...

sorry to sound stupid, but how do you run this script? Thank you for the help in advance.

 
February 1, 2007 4:16 PM
Blogger Bharat said...

Copy the code to notepad and save it with a vbs extension. When saving, make sure the "Save As Type:" is set to "All Files" and not "Text Documents (txt)".

Recommend running scripts using cscript - if it's not your default engine you can use:
cscript myscriptname.vbs

 
May 14, 2007 1:40 PM
Anonymous Anonymous said...

If you have problems running it (I did) remove the " _" from lines 8 and 9.

 
June 28, 2007 6:08 PM
Blogger Brian said...

Here's another take on getting the service tag. This one asks for the host name and gives the resulting service tag in a popup.


On Error Resume Next
Dim strComputer
strComputer = InputBox("Enter the name of DELL Computer:")
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colSMBIOS = objWMIService.ExecQuery ("Select * from Win32_SystemEnclosure")
For Each objSMBIOS in colSMBIOS
MsgBox strComputer & ": " & objSMBIOS.SerialNumber
Next

 
July 5, 2007 5:55 AM
Anonymous Anonymous said...

how would you modify this to get serial number of say HP or IBM machines

 
August 10, 2007 2:15 PM
Anonymous Anonymous said...

here's the code that I use to process IBM/LENOVO gear...it's a snippet of larger program so you might have to do some cleanup.


Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery( _
"SELECT * FROM Win32_ComputerSystem",,48)
For Each objItem in colItems
mfg = objItem.Manufacturer
model = objItem.Model 'Model
sysname = LCase(objItem.Name) 'System Name
systype = objItem.SystemType 'System Type

Set colItems = objWMIService.ExecQuery( _
"SELECT * FROM Win32_ComputerSystemProduct",,48)
For Each objItem in colItems
machver = objItem.Version 'Version
Next


IF (StrComp(mfg,"LENOVO") = 0) Then
sysmodel = Mid(model,1,4)
systype = Mid(model,4,3)
End If

Wscript.Echo("Vendor: " + mfg + vbCrLf + "host: " + sysname + vbCrLf + "OS: " + osname + vbCrLf + "OS Ver: " + osver + vbCrLf + "Make: " + machver + vbCrLf + "Type: " + systype + vbCrLf + "Model: " + sysmodel + vbCrLf + "Serial #: " + serialno)

 
August 22, 2007 11:12 AM
Anonymous Anonymous said...

Hey dude i tried ur scripts the first one is not working for me incase if u can write a script which generates the service tag along with machine name in my domain it would be wonderfull:)

- Brijendra Shukla

 
February 4, 2008 12:47 PM
Anonymous freemantim said...

thanks for the script. handy little tool.

is there a way to have the output dumped to a CSV file?

 
June 9, 2008 1:53 PM
Anonymous Anonymous said...

To save the output as a CSV file:

1- change the line:
Wscript.Echo strComputer & ": " & objSMBIOS.SerialNumber

to:
Wscript.Echo strComputer & "," & objSMBIOS.SerialNumber

2- run the script as:
cscript myscriptname.vbs > results.csv

Ronaldo Radunz

 

Post a Comment

Links to this post:

Create a Link

<< Home