Here is a script to rename the computer
Make sure you add /NewName:YourNewComputerName in the script parameters and obviously change it for your naming.
Also note that each computer requires a unique name on the network to prevent conflicts so ensure the new name is unique.
strComputerName = WScript.Arguments.Named("NewName")
If strComputerName <> "" then
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & "." & "\root\cimv2")
Set colComputers = objWMIService.ExecQuery ("Select Name from Win32_ComputerSystem")
For Each objComputer in colComputers
wscript.echo "Old Computer Name: " & objComputer.Name
wscript.echo "New Computer Name: " & strNewName
If objComputer.Name <> strNewName Then
' rename this computer
intErrorCode = objComputer.Rename(strComputerName)
' now reboot
Reboot
End if
Next
Else
wscript.echo "Please define a computer name!"
End If
Sub Reboot()
dim strComputer, objWMIService, colOS, objOS
strComputer = "."
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate,(Shutdown)}!\\" & strComputer & "\root\cimv2")
Set colOS = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")
For Each objOS in colOS
objOS.Reboot()
Next
End Sub
2 Comments
The argument didn’t seem to work for me. I uploaded the script to my dashboard & assigned it to run on a PC. The output was as follows:
Summary: Old Computer Name: WINDOWS-K31NQU9
New Computer Name:
(i.e. the new computer name argument apparently wasn’t processed…?)
I passed the argument to the script from the dashboard as follows:
/NewName:Impala13
(I used no space after the colon. Was I supposed to? I guess I’ll try again & add the space. I just thought I’d see whether you had any tips.
Also FYI we have seen in the past where the GFI MAX dashboard seems to interpret an argument even when none is present. We ended up having to modify our scripts to sanitize the argument received and if it was not of the format expected, just behave as though no argument is passed. As a result, I am a bit mistrusting of whether the dashboard could be at fault here, and not your script or me… 🙂
Thanks so much!
–
Doug
Hey Doug,
That’s very strange, looks like you are doing it correctly.
No Space should be required after the colon.
Max always passes the /LogFile parameter to each script, which is why I’ve done it that way.
Easiest way would be to test on a script that enumerates all the parameters passed to make sure its actually working.