Vbscript / Operating System / Rename Dell Machine By Service Tag
The following code will read the service tag from a Dell machine and rename the machine using the service tag. This allows a correlation between the physical asset tag and the machine name in AD and simplifies the management process.
Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator") Set objWMIService = objSWbemLocator.ConnectServer(strComputer, "root\cimv2") Set colSMBIOS = objWMIService.ExecQuery("Select * from Win32_SystemEnclosure") For Each objSMBIOS in colSMBIOS strSTag = objSMBIOS.SerialNumber Next
strComputer = "." 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(strSTag) Next
strPCName = "PC" & strSTag
Set colComputers = objWMIService.ExecQuery("Select * from Win32_ComputerSystem")
For Each objComputer in colComputers intErr = objComputer.Rename(strPCName) Next
Please note that a disclaimer applies to any code on this page.
|