Rename Computer Model Number & Service Tag

email me

This script allows you to name a computer using the model number and service tag.  Just throw it into your imaging/deployment process, and you can automate the naming portion of your imaging.

on error resume next

'returns service tag
Dim computername
strComputer = "."

Set objWMIservice = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
set colitems = objWMIservice.ExecQuery("Select * from Win32_BIOS",,48)
For each objitem in colitems
'for testing only
'Wscript.echo "Dell Service Tag: " & objitem.serialnumber
computername = objitem.serialnumber

Next

'returns machine model number only
'PRIMARY MODEL DETECTION
Set objWMI = GetObject("winmgmts:")
Set colSettings = objWMI.ExecQuery("Select * from Win32_ComputerSystem")

For Each objComputer in colSettings
LaptopModel = Trim(objComputer.Model)
Next

Select Case LaptopModel

Case "HP EliteBook 8470p"
strModel = "8470"

Case "HP EliteBook 8460p"
strModel = "8460"

Case "HP EliteBook 8450p"
strModel = "8450"

Case "HP EliteBook 8440p"
strModel = "8440"

Case "HP EliteBook 6930p"
strModel = "6930"

Case "HP EliteBook 2530p"
strModel = "2530"

Case "HP EliteBook 2540p"
strModel = "2540"

Case "HP Compaq dc7900 Small Form Factor"
strModel = "7900"

Case "HP Compaq 8000 Elite SFF PC"
strModel = "8000"

Case "HP Compaq 8200 Elite SFF PC"
strModel = "8200"

Case "OptiPlex 755"
strModel = "755"

Case "OptiPlex 745"
strModel = "745"

Case "Latitude D630"
strModel = "630"

Case "Latitude D620"
strModel = "620"

Case "Latitude D430"
strModel = "430"

End Select

'SECONDARY MODEL DETECTION
if strModel = "" then
'msgbox "no model was detected"
myLength = Len(LaptopModel)

For i = 1 To myLength
If Asc(Mid(LaptopModel, i, 1)) <> 32 Then
If Asc(Mid(LaptopModel, i, 1)) >= 48 And Asc(Mid(LaptopModel, i, 1)) <= 57 Then
myNumber = myNumber & Mid(LaptopModel, i, 1)
End If
Else
'msgbox("no numeric")
End If
Next
'msgbox(myNumber)
strModel = myNumber
end if

'for testing only
'msgbox strModel

'renames machine with model number - service tag
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colComputers = objWMIService.ExecQuery ("Select * from Win32_ComputerSystem")

For Each objComputer in colComputers
err = objComputer.Rename(strModel & "-" & computername)
Next

WScript.Quit(0)