Renaming Computer Accounts

Microsoft® Windows® 2000 Scripting Guide

microsoft windows 2000 scripting guide

« Previous | Next »   

If you rename a computer for any reason, you must also rename the computer account. Although it is generally best to rename both the computer and the computer account at the same time, this is not always possible. For example, a computer might be transferred to a new department and thus need be renamed to reflect departmental standards. If the new user does not have the right to rename the computer account in Active Directory, however, a discrepancy will exist between the computer name and the computer account name. This is not an unusual scenario; many organizations place strict limits on the modifications users can make to any object stored in Active Directory.

In a situation such as this, a person with the right to rename the computer account will have to rename the computer account to match the new computer name.

You can rename a computer account by using the ADSI MoveHere method. Using the MoveHere method, the script binds to a computer account and then moves the account. Rather than moving the account to a new OU or another new container, however, the script leaves the account in the same OU, but "moves" it to a new account name.

For example, to rename a computer account named ComputerA in the Finance OU, you "move" the computer account to a new account named ComputerB, also located in the Finance OU. This has the same effect as renaming the account. The account named ComputerA disappears, and the information previously stored in that account is now stored in the new account named ComputerB.

Scripting Steps

Listing 9.7 contains a script that renames a computer account. To carry out this task, the script must perform the following steps:

  1. Use a GetObject call to bind to the Active Directory container in which the computer account is stored.
  2. Use the MoveHere method with the following two parameters:
    • The object to be renamed ("LDAP://CN=Workstation4, OU=Finance, DC=fabrikam, DC=com").
    • The new common name for the object ("CN=Workstation5").

Listing 9.7   Renaming a Computer Account

1 2 3 4 
Set objNewOU = GetObject("LDAP://OU=Finance, DC=fabrikam, DC=com") Set objMoveComputer = objNewOU.MoveHere _     ("LDAP://CN=Workstation4, OU=Finance, DC=fabrikam, DC=com", _         "CN=Workstation5")

When this script is run, the computer account Workstation4 is renamed to Workstation5. The account remains in the Finance OU.


send us your feedback Send us your feedback « Previous | Next »   


Microsoft Windows 2000 Scripting Guide(c) Automating System Administration 2003
Microsoft Windows 2000 Scripting Guide(c) Automating System Administration 2003
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 635

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