Need a script to change the name of a computer

Page 1 of 2 12 LastLast

  1. Posts : 93
    Windows 7 Professional 32bit
       #1

    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 Computer


  2. Posts : 2,737
    Windows 7 Enterprise (x64); Windows Server 2008 R2 (x64)
       #2

    Where is the variable you need? or are you talking about VMHOST variable and using it?
      My Computer


  3. Posts : 93
    Windows 7 Professional 32bit
    Thread Starter
       #3

    Using the VMHOST variable.
      My Computer


  4. Posts : 2,737
    Windows 7 Enterprise (x64); Windows Server 2008 R2 (x64)
       #4

    Cancerous said:
    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


  5. Posts : 93
    Windows 7 Professional 32bit
    Thread Starter
       #5

    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


  6. Posts : 2,737
    Windows 7 Enterprise (x64); Windows Server 2008 R2 (x64)
       #6

    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


  7. Posts : 93
    Windows 7 Professional 32bit
    Thread Starter
       #7

    Thanks.
    I'll test it on Monday when I get back to work.
      My Computer


  8. Posts : 2,737
    Windows 7 Enterprise (x64); Windows Server 2008 R2 (x64)
       #8

    Great, don't forget to let me know if it works or not. -WS
      My Computer


  9. Posts : 93
    Windows 7 Professional 32bit
    Thread Starter
       #9

    I get the "Unexpected switch at this level" error.
      My Computer


  10. Posts : 2,737
    Windows 7 Enterprise (x64); Windows Server 2008 R2 (x64)
       #10

    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


 
Page 1 of 2 12 LastLast

  Related Discussions
Our Sites
Site Links
About 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 12:09.
Find Us