Remotely rename PCs?

thirdeye

Platinum Member
Jun 19, 2001
2,610
0
76
www.davewalter.net
I'm not sure that this is even possible but it would be nice to do since I have a bunch of workstations that don't adhere to a common naming scheme. Is there a command/tool that would facilitate this action without me having to go to each and every machine and kick the user, log in, change the name, then reboot?

Any insight would be appreciated. As a disclaimer if it involves scripting, you'll have to pretty much spell it out, since I'm not overly familiar with scripting yet.
 

FoBoT

No Lifer
Apr 30, 2001
63,084
14
81
fobot.com
vbscript

renaming requires a reboot, so even if you script it, the box has to reboot before the name change happens
this code works with xp and server 2003, it may or may not work with windows 2000, i am not sure
Set oShell = WScript.createObject("WScript.shell")
Set WshNetwork = WScript.CreateObject("WScript.Network")
strOldName = WshNetwork.ComputerName
strComputer = "."
strNewName = "NewComputerName"
'this renames the computer
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(strNewName)
Select Case err
Case "0"
WScript.Echo "Success!"
Case Else
WScript.Echo "Failure!"
WScript.Quit
End Select
Next
'this reboots the computer
strComputer = strOldName
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate,(Shutdown)}!\\" & strComputer & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
ObjOperatingSystem.Reboot()
Next
WScript.Quit
 

thirdeye

Platinum Member
Jun 19, 2001
2,610
0
76
www.davewalter.net
Ok, I figured out how to get it to rename my local machine. What would I have to do in order for it to look at another machine on my network named testpc01 and change it to jsmith?
 

FoBoT

No Lifer
Apr 30, 2001
63,084
14
81
fobot.com
you have to run the script on that computer

i don't know of any remote way to do that. if you have a remote way to run scripts (like logon scripts if you are on a domain), then you can use that