Change Computer Name to Serial

Little Windows VBS script to pull Dell BIOS serial tags into Computer Names. I pulled this from an old backup, since it got removed a long time ago for whatever reason.

strUser = "Administrator"
strPassword = "P@ssw0rd"

Set objNetwork = CreateObject("WScript.Network")
	strComputer = objNetwork.ComputerName

Set objComputer = GetObject("winmgmts:{impersonationLevel=Impersonate}!\\" & _
	strComputer & "\root\cimv2:Win32_ComputerSystem.Name='" & _
		strComputer & "'")

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem",,48)
For Each objItem in colItems
	strMsg = objItem.Caption
	If strMsg = "Microsoft Windows XP Professional" Then

		winmgmt1 = "winmgmts:{impersonationLevel=impersonate}!//."
		'WScript.Echo winmgmt1
			Set SNSet = GetObject( winmgmt1 ).InstancesOf ("Win32_BIOS")
			for each SN in SNSet

				If SN.SerialNumber = strComputer Then
					MsgBox "Computer name already set! Name is: "& strComputer
				End If

				If SN.SerialNumber = "" Then
					MsgBox "Problem with computer naming!"
				End If

				ErrCode = objComputer.Rename(SN.SerialNumber, strPassword, strUser)

				If ErrCode = 0 Then
					MsgBox "Computer renamed successfully to: "& SN.SerialNumber
				End If


	End If

Leave a Reply

Your email address will not be published. Required fields are marked *

Post Navigation