Share This Post

VBScript to name computers during OSD

Determining a computer name during an imaging process has always proved to be a challenge. One of my favorite methods is to utilize WMI to obtain the serial number of the computer that is being imaged. This way, if all your hardware is from a particular vendor, Dell, HP, Panasonic, you can guarantee that no two computer names will ever be the same and you can name them automatically during the imaging process. Not to mention you can quickly look up the computer information on the vendor website.

The following vbscript I wrote will determine the serial number, append a "C" to the front of it, then populate the OSD task sequence variable called "OSDComputerName". It is one of the first tasks in all my task sequences. One of the extras I wrote in will actually prompt you to enter the computer name if it detects it is a VMWare or Microsoft Virtual machine, because they do not have a serial number in WMI. Enjoy!

‘GetComputerName.vbs
‘Joe Clarke 5/7/2010

set env = CreateObject("Microsoft.SMS.TSEnvironment")

‘Get relevant computer information
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystemProduct", "WQL", _
wbemFlagReturnImmediately + wbemFlagForwardOnly)

For Each objItem In colItems
strSerialNum = objItem.IdentifyingNumber
Next

Name = "C" & strSerialNum
UCase(Name)

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem", "WQL", _
wbemFlagReturnImmediately + wbemFlagForwardOnly)

For Each objItem In colItems
If InStr(objItem.Manufacturer, "VMware") Then
Do
namechosen = "Acceptable"
Name = inputbox("Please enter the new computer name. " ,"Prompt for Computer Name:",,400,0)
‘Check to ensure the field is not blank
If Name = "" Then
msgbox "You cannot leave this field blank."
namechosen = "NoGood"
End If
Loop Until namechosen = "Acceptable"

End If
If InStr(objItem.Manufacturer, "Microsoft Corporation") Then
Do
namechosen = "Acceptable"
Name = inputbox("Please enter the new computer name. " ,"Prompt for Computer Name:",,400,0)
‘Check to ensure the field is not blank
If Name = "" Then
msgbox "You cannot leave this field blank."
namechosen = "NoGood"
End If
Loop Until namechosen = "Acceptable"
End If

Next

env("OSDComputerName") = Name

Share This Post

1 Comment

  1. Hi Joe

    Do you perhaps have a VBscript to name computers with a company asset tag instead of using a serial number? I am building a win7 machine and the default name is minint. I need to a script where I can edit the name or have sccm prompt for a PC name. Please help. Thanks

Leave a Reply