Windows Scripting
  Home arrow Windows Scripting arrow Page 3 - Moving and Renaming Computers with Active ...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
WINDOWS SCRIPTING

Moving and Renaming Computers with Active Directory
By: O'Reilly Media
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 2
    2008-01-17

    Table of Contents:
  • Moving and Renaming Computers with Active Directory
  • Moving a Computer to a New Domain
  • Renaming a Computer
  • Add or Remove a Computer Account from a Group

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Moving and Renaming Computers with Active Directory - Renaming a Computer


    (Page 3 of 4 )

    Problem

    You want to rename a computer.

    Solution

    Using a graphical user interface

    1. Log on to the computer either directly or with a remote console application such as Terminal Services.

    2. Open the Control Panel and double-click on the System applet.
    3. Select the Computer Name tab and click the Change button.
    4. Under Computer Name, type the new name of the computer and click OK until you are out of the System applet.
    5. Reboot the machine.

    Using a command-line interface

    You can rename a computer object by using the built-in netdom utility with the following syntax:

      > netdom renamecomputer <ComputerName>  /NewName <NewComputerName> /UserD
      <DomainUserUPN> /PasswordD * /UserO <ComputerAdminUser> /PasswordO * /Reboot

    Using VBScript

      ' This code renames a computer in AD and on the host itself.
      ' ------ SCRIPT CONFIGURATION ------
      strComputer     = "<ComputerName>"    ' e.g. joe-xp
      strNewComputer  = "<NewComputerName>" ' e.g. joe-pc
      strDomainUser   = "<DomainUserUPN>"   ' e.g.
    administrator@rallencorp.com
      strDomainPasswd = "<DomainUserPasswd>"
      strLocalUser = "<ComputerAdminUser>" 'e.g. joe-xp\administrator
     
    strLocalPasswd  = "<ComputerAdminPasswd>"
      ' ------ END CONFIGURATION ---------

      '###########################
      ' Connect to Computer
      '###########################
      set objWMILocator = CreateObject("WbemScripting.SWbemLocator") 
     objWMILocator.Security_.AuthenticationLevel = 6
      set objWMIComputer = objWMILocator.ConnectServer(strComputer, _
                               "root\cimv2", _
                               strLocalUser, _
                                strLocalPasswd)
      set objWMIComputerSystem = objWMIComputer.Get( _
              "Win32_ComputerSystem.Name='" & _
              strComputer & "'")
      '###########################
      ' Rename Computer
      '###########################
      rc = objWMIComputerSystem.Rename(strNewComputer, _
                    strDomainPasswd, _
                    strDomainUser)
      if rc <> 0 then
          WScript.Echo "Rename failed with error: " & rc
      else
          WScript.Echo "Successfully renamed " & strComputer & " to " & _
                       strNewComputer
      end if

      WScript.Echo "Rebooting . . . "
      set objWSHShell = WScript.CreateObject("WScript.Shell")
      objWSHShell.Run "rundll32 shell32.dll,SHExitWindowsEx 2"

    Discussion

    Renaming a computer consists of two operations: renaming the computer object in Active Directory and renaming the hostname on the machine itself. To do it in one step, which each of the three solutions offers, you must have permission in Active Directory to rename the account and administrator permissions on the target machine. For the rename operation to be complete, you must reboot the computer.

    In some cases, renaming a computer can adversely affect services running on the computer. For example, you cannot rename a machine that is a domain controller, Exchange Server, or a Windows Certificate Authority without taking additional steps and precautions.

    Using a graphical user interface

    After you rename the computer, you will be prompted to reboot the machine. You can cancel if necessary, but you’ll need to reboot at some point to complete the rename operation.

    Using a command-line interface

    The renamecomputer option in netdom is new to Windows Server 2003. It can run remotely and includes a /Reboot switch that allows you to automatically reboot the computer after the rename is complete.

    Using VBScript

    The Win32_ComputerSystem::Rename method must be run on the local machine unless the computer is a member of a domain. Unlike the GUI and CLI solutions, you cannot specify alternate credentials for the connection to the computer other than domain credentials. For this reason, the user and password you use with the Rename method must have administrative privileges on the target machine (i.e., part of the Administrators group) and on the computer object in Active Directory.

    TheRenamemethod is new in Windows XP and Windows Server 2003, and is not available on Windows 2000 and earlier machines.

    See Also

    Recipe 4.23 for renaming objects, MS KB 228544 (Changing Computer Name in Windows 2000 Requires Restart), MS KB 238793 (Enhanced Security Joining or Resetting Machine Account in Windows 2000 Domain), MS KB 260575 (How to Use Netdom.exe to Reset Machine Account Passwords of a Windows 2000 Domain Controller), MS KB 325354 (How to Use the Netdom.exe Utility to Rename a Computer in Windows Server 2003), and MSDN: Win32_ComputerSystem::Rename

    More Windows Scripting Articles
    More By O'Reilly Media


       · This article is an excerpt from the book "Active Directory Cookbook, Second...
     

    Buy this book now. This article is excerpted from chapter eight of the Active Directory Cookbook, Second Edition, written by Robbie Allen and Laura E. Hunter (O'Reilly; ISBN: 059610202X). Check it out today at your favorite bookstore. Buy this book now.

    WINDOWS SCRIPTING ARTICLES

    - More Windows Scripting Workarounds from Nilpo
    - Overloading Methods and More in VBScript
    - Improving MFC for Windows Vista
    - Regular Expressions in VBScript
    - Working with Dates in WMI
    - Completing Calendars with VBScript Date Func...
    - Building Calendars with VBScript Date Functi...
    - Working With Dates and Times in VBScript
    - Designing WCF DataContract Classes Using the...
    - Understanding Dates and Times in VBScript
    - Working With Arrays in VBScript
    - Compressed Folders in WSH
    - Using .NET Interops in VBScript
    - Nilpo`s Scripting Secrets, Vol I
    - Database operations using Silverlight 2.0 WC...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
    Stay green...Green IT