Windows 7 Forums

Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide 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

03 Feb 2012   #1
Cancerous

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
.

03 Feb 2012   #2
WindowsStar

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
03 Feb 2012   #3
Cancerous

Windows 7 Professional 32bit
 
 

Using the VMHOST variable.
My System SpecsSystem Spec
.


03 Feb 2012   #4
WindowsStar

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
03 Feb 2012   #5
Cancerous

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
04 Feb 2012   #6
WindowsStar

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
04 Feb 2012   #7
Cancerous

Windows 7 Professional 32bit
 
 

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

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
05 Feb 2012   #9
Cancerous

Windows 7 Professional 32bit
 
 

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

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




Thread Tools





Similar help and support threads
Thread Forum
Visual Basic Script Change
Someone who knows Visual Basic Scripting, help me with a script that was handed to me, but it's not complete and can use a few adjustments to it. The script is a little advanced, just a forewarning :)
Software
how to change his script?
how to change his script?
General Discussion
The text under my icons changed to script? How do I change it back?
Hey guys: That pretty much sums it up. I don't know what happened but now it's really annoying to read the icons because their in script. How do I change it back to normal? Actually, everything is now in script, including the start menu and all other sub-menus. Fudge... Thanks
Software
Script to change power settings
Greetings, I am attempting to temporarily disable hibernate and make sure the monitor doesn't go off while I am running a script to complete system configuration. control powercfg.cpl -monitor-timeout-ac 30 control powercfg.cpl -monitor-timeout-dc 30 control powercfg.cpl /hibernate off
Performance & Maintenance
need to change input language for new users via registry script
Hello, I need script or string by regedit to change input language for new user accounts to Portuguese (Portugal) - Portuguese. Thanks
General Discussion
Change default program through script
Hi guys, I'm in a new IT job for a computer lab and I'm picking up skills for maintaining it as I go along. I need to change the default program for a filetype on all machines in the lab. If I just log on as admin and change it under my account, the change doesn't persist for the non-admin...
General Discussion

Our Sites

Site Links

About Us

Find Us

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

All times are GMT -5. The time now is 00:00.

Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App