Need a script to change the name of a computer

Cancerous

New member
Power User
Local time
4:52 PM
Messages
93
About to roll out a bunch of VM's onto a domain, but I need to know how to automate a computer name change based on a variable BEFORE it joins the domain.

I've got a cmd script in SetupComplete.cmd that goes to a website to get a hostname based on the computers IP.
So is there any way to automate a script to get the variable and assign it as the host name?

This is the script I use to get the hostname. It assigns the hostname to the variable VMHOST.
Code:
for /f "delims=" %a in ('c:\windows\system32\webfetch.exe websiteurl.php') do @set VMHOST=%a
 

My Computer My Computer

OS
Windows 7 Professional 32bit
Where is the variable you need? or are you talking about VMHOST variable and using it?
 

My Computer My Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
Dell OP7010
OS
Windows 7 Enterprise (x64); Windows Server 2008 R2 (x64)
Memory
16GB
Monitor(s) Displays
4 Dell 24" LCD
Screen Resolution
1280x1024
Keyboard
Dell
Mouse
Dell Optical
Internet Speed
40meg
Using the VMHOST variable.
 

My Computer My Computer

OS
Windows 7 Professional 32bit
Using the VMHOST variable.

I am not sure if I know how to rename the machine from the command line. I would have to look that up. I can turn all of it into VBScript for you, unless you don't know VBScript and need to manage it???? Let me know. -WS
 

My Computer My Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
Dell OP7010
OS
Windows 7 Enterprise (x64); Windows Server 2008 R2 (x64)
Memory
16GB
Monitor(s) Displays
4 Dell 24" LCD
Screen Resolution
1280x1024
Keyboard
Dell
Mouse
Dell Optical
Internet Speed
40meg
I'm sure I'll cope. I have a tiny little bit of coding experience, so if it's just changing some variables then it will be fine.
& I work in a software company so I'm sure one of the developers will know how to use vbscript.
 

My Computer My Computer

OS
Windows 7 Professional 32bit
Here you go. I just modified your command line command. Please note: You can get into some major trouble if the name is longer than 15 characters. There is NO name checking here. Please test this on a machine that if it crashes you are ok with that. Let me know -WS

Code:
for /f "delims=" %a in ('c:\windows\system32\webfetch.exe websiteurl.php') do @wmic computersystem where name="%COMPUTERNAME%" call rename name=%a
 

My Computer My Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
Dell OP7010
OS
Windows 7 Enterprise (x64); Windows Server 2008 R2 (x64)
Memory
16GB
Monitor(s) Displays
4 Dell 24" LCD
Screen Resolution
1280x1024
Keyboard
Dell
Mouse
Dell Optical
Internet Speed
40meg
Thanks.
I'll test it on Monday when I get back to work.
 

My Computer My Computer

OS
Windows 7 Professional 32bit
Great, don't forget to let me know if it works or not. -WS
 

My Computer My Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
Dell OP7010
OS
Windows 7 Enterprise (x64); Windows Server 2008 R2 (x64)
Memory
16GB
Monitor(s) Displays
4 Dell 24" LCD
Screen Resolution
1280x1024
Keyboard
Dell
Mouse
Dell Optical
Internet Speed
40meg
I get the "Unexpected switch at this level" error.
 

My Computer My Computer

OS
Windows 7 Professional 32bit
Does the following give you the computer name?

Code:
for /f "delims=" %a in ('c:\windows\system32\webfetch.exe websiteurl.php') do @echo %a

If yes, on a test machine does this change the name?

Code:
wmic computersystem where name="%COMPUTERNAME%" call rename name=Test-PC
or
Code:
wmic computersystem where name="%COMPUTERNAME%" call rename name="Test-PC"
 

My Computer My Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
Dell OP7010
OS
Windows 7 Enterprise (x64); Windows Server 2008 R2 (x64)
Memory
16GB
Monitor(s) Displays
4 Dell 24" LCD
Screen Resolution
1280x1024
Keyboard
Dell
Mouse
Dell Optical
Internet Speed
40meg
I'm doing it using wsname.exe now.

Code:
for /f "delims=" %a in ('c:\windows\system32\webfetch.exe websiteurl.php') do @set VMHOST=%a

wsname.exe /N:%VMHOST%

That works :)
Not it's just a matter of getting it to work with sysprep :(
 

My Computer My Computer

OS
Windows 7 Professional 32bit
Back
Top