Recipe 8.5 Renaming a Computer

8.5.1 Problem

You want to rename a computer.

8.5.2 Solution

8.5.2.1 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.

8.5.2.2 Using a command-line interface
> netdom renamecomputer <ComputerName> /NewName <NewComputerName> /UserD[RETURN] <DomainUserUPN> /PasswordD * /UserO <ComputerAdminUser> /PasswordO * /Reboot
8.5.2.3 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"

8.5.3 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 offer, 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 Windows 2000 domain controller or a Windows Certificate Authority without first removing those services.

8.5.3.1 Using a graphical user interface

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

8.5.3.2 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.

8.5.3.3 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.

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

8.5.4 See Also

Recipe 4.19 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



Active Directory Cookbook
Active Directory Cookbook, 3rd Edition
ISBN: 0596521103
EAN: 2147483647
Year: 2006
Pages: 456

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net