Rename a computer to based on Asset Tag or Serial Number
To rename a computer based on its Asset Tag/Serial number using a script, you can put the following text in a vbs file. I use NL-AMS-WS- preceding the Asset tag to indicate the country (Netherlands), city (Amsterdam) and type (Workstation):
'***********************************************************************
'
' Changes the computer name to the computer's serial number/asset tag.
'
'***********************************************************************
strComputer = "."
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
'Part 1 - Acquire serial/service tag number
Set colSMBIOS = objWMIService.ExecQuery ("Select * from Win32_SystemEnclosure")
For Each objSMBIOS in colSMBIOS
strSN = objSMBIOS.SerialNumber
If strSN <> "" Then exit For
Next
'Part 2 - Assign computer name to serial/service tag number
Name = "NL-AMS-WS" & strSN
Set colComputers = objWMIService.ExecQuery ("Select * from Win32_ComputerSystem")
For Each objComputer in colComputers
err = objComputer.Rename(name)
if err <> 0 then
wscript.echo "There was an error renaming the machine. Please restart, and try again."
else
wscript.echo "Machine successfully renamed: " & Name
end if
Next
To use this during deployment you can use the following command:
cscript scriptname.vbscommand line, microsoft, script, vbs, windows