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
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: Scripts

Exchangepedia Blog is read by visitors from all 50 US States and 150 countries world-wide

17 Comments:
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!
Works for PCs as well as servers!
Works for PCs as well as servers!
sorry to sound stupid, but how do you run this script? Thank you for the help in advance.
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
If you have problems running it (I did) remove the " _" from lines 8 and 9.
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
how would you modify this to get serial number of say HP or IBM machines
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)
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
thanks for the script. handy little tool.
is there a way to have the output dumped to a CSV file?
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
Could this script be reversed, so I could query the Dell service tag to get the computer name?
Easier method (atleast for me) :). Open a command prompt type in:
Wmic bios get serialnumber.
This could be used with remote machines as well.
wmic /user:administrator /node:machinename bios get serialnumber
@vizworld
Thanks for the quick and easy command!
I've been using this one for a long time, it's so easy!
Wmic bios get serialnumber.
thanks for saving me a trip to the client site!
Post a Comment
Links to this post:
Create a Link
<< Home