Windows 7 Forums Search
Welcome to Windows 7 Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows 7. The Windows 7 forum also covers news and updates and has an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.


Windows 7 - Need a script to change the name of a computer

 
02-03-2012   #1


Windows 7 Professional 32bit
 
 

Need a script to change the name of a computer

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 System SpecsSystem Spec
02-03-2012   #2


Windows 7 Enterprise (x64); Windows Server 2008 R2 (x64)
 
 


Where is the variable you need? or are you talking about VMHOST variable and using it?
My System SpecsSystem Spec
02-03-2012   #3


Windows 7 Professional 32bit
 
 


Using the VMHOST variable.
My System SpecsSystem Spec
.


02-03-2012   #4


Windows 7 Enterprise (x64); Windows Server 2008 R2 (x64)
 
 


Quote   Quote: Originally Posted by Cancerous View Post
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 System SpecsSystem Spec
02-03-2012   #5


Windows 7 Professional 32bit
 
 


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 System SpecsSystem Spec
02-04-2012   #6


Windows 7 Enterprise (x64); Windows Server 2008 R2 (x64)
 
 


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 System SpecsSystem Spec
02-04-2012   #7


Windows 7 Professional 32bit
 
 


Thanks.
I'll test it on Monday when I get back to work.
My System SpecsSystem Spec
02-04-2012   #8


Windows 7 Enterprise (x64); Windows Server 2008 R2 (x64)
 
 


Great, don't forget to let me know if it works or not. -WS
My System SpecsSystem Spec
02-05-2012   #9


Windows 7 Professional 32bit
 
 


I get the "Unexpected switch at this level" error.
My System SpecsSystem Spec
02-07-2012   #10


Windows 7 Enterprise (x64); Windows Server 2008 R2 (x64)
 
 


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 System SpecsSystem Spec
Reply

 Need a script to change the name of a computer problems?



Thread Tools



Similar Threads for: Need a script to change the name of a computer
Thread Forum
how to change his script? General Discussion
Solved The text under my icons changed to script? How do I change it back? Software
Batch script to change how applications open from shortcuts General Discussion
Solved Script to change power settings Performance & Maintenance
Change default program through script General Discussion


All times are GMT -5. The time now is 04:31 PM.



Windows 7 Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows 7" and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd
  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30