Re: Script to Rename Computer Name in Domain



Skepper wrote:


i looking a script to rename computer name in domain server 2003

something in VB + MassageBox [Enter New Computer Name]

include user name + password to change it (domain remember ...)



To rename a computer you bind to the parent OU/Container of the computer
object in AD and use the MoveHere method. See this link:

http://www.microsoft.com/technet/scriptcenter/scripts/ad/computer/cptrvb13.mspx

This changes the "Common Name" of the object. If you want to rename the
local computer (change the NetBIOS name), you must run a script must run a
script locally at the computer that uses WMI. See this link:

http://www.microsoft.com/technet/scriptcenter/scripts/ad/computer/cptrvb14.mspx

In either case, you can prompt for the new name with an InputBox statement
in VBScript. I assume you intend the script to be run at the computer in
question. Otherwise, you would need to also prompt for the current name.
Assuming the script is run locally, and you are changing the Common Name,
the VBScript program could be similar to:
==========
Option Explicit

Dim objSysInfo, strComputerDN, objComputer
Dim strNewName, strParentAdsPath, objParent

' Prompt for new computer name.
strNewName = InputBox("Enter new computer name")

' Retrieve local computer Distinguished Name.
Set objSysInfo = CreateObject("ADSystemInfo")
strComputerDN = objSysInfo.ComputerName

' Bind to the local computer object.
Set objComputer = GetObject("LDAP://"; & strComputerDN)

' Bind to the parent OU/container of computer object.
strParentAdsPath = objComputer.Parent
Set objParent = GetObject(strParentAdsPath)

' Rename the computer object.
objParent.MoveHere objComputer.AdsPath, "cn=" & strNewName)
========
The above assumes the user has permissions to rename the computer object. If
not, you can use alternate credentials. I would recommend prompting for the
credentials, rather than hard coding a password in the script. For example,
you would need the additional code below (assumes you have already assigned
a value to variable strComputerDN):
=========
Option Explicit

Dim objSysInfo, strComputerDN, objComputer
Dim strNewName, strParentAdsPath, objParent
Dim strUser, strPassword, objNS

Const ADS_SECURE_AUTHENTICATION = &H1
Const ADS_SERVER_BIND = &H200

' Prompt for new computer name.
strNewName = InputBox("Enter new computer name")

' Prompt for administrator user name and password.
strUser = InputBox("Enter admin user name in form Domain\AdmName")
strPassword = InputBox("Enter password")

' Retrieve local computer Distinguished Name.
Set objSysInfo = CreateObject("ADSystemInfo")
strComputerDN = objSysInfo.ComputerName

' Bind to the local computer object.
Set objComputer = GetObject("LDAP://"; & strComputerDN)

' Bind to the parent OU/container of computer object using alternate
credentials.
strParentAdsPath = objComputer.Parent
Set objNS = GetObject("LDAP:")
Set objParent = objNS.OpenDSObject(strParentAdsPath, strUser, strPassword, _
ADS_SERVER_BIND Or ADS_SECURE_AUTHENTICATION)

' Rename the computer object.
objParent.MoveHere objComputer.AdsPath, "cn=" & strNewName)
========
The user name can be in the format

<NT name of user>\<NetBIOS name of domain>

where the NT name of the user is the "pre-Windows 2000 logon name"
(sAMAccountName). Or it can be the Distinguished Name of the user, or it can
be the userPrincipalName, such as "jsmith@xxxxxxxxxxxx".

If you want to change the NetBIOS name of the computer (per the second link
above) using WMI, you would provide alternate credentials using the
SWbemLocator object. See this link:

http://www.microsoft.com/technet/scriptcenter/guide/sas_wmi_ciga.mspx

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--


.



Relevant Pages

  • Re: Script to Rename Computer Name in Domain
    ... To rename a computer you bind to the parent OU/Container of the ... the local computer, you must run a script ... you can prompt for the new name with an InputBox ... ' Bind to the local computer object. ...
    (microsoft.public.windows.server.scripting)
  • Re: Rename PC input
    ... > I'm trying to create a script to prompt for input, rename the PC based on ... > that input and return proper error messages. ... Based on the nature of the prompt ("... ...
    (microsoft.public.windows.server.scripting)
  • Re: LDAP query information
    ... a "Dim" statement. ... execution of the script. ... ' Filter on computer object. ... ' Construct LDAP syntax query. ...
    (microsoft.public.windows.server.scripting)
  • Re: Rename File Using Strring Found in File?
    ... OK, thanks, but the script does not seem to rename the files. ... # sleep 1; ... to the string in this particular file that I want to match. ...
    (comp.lang.perl.misc)
  • Re: rename a local group in windows 2003
    ... strComputer = objShell.ExpandEnvironmentStrings ... I tried to rename several local groups using the MoveHere method ... Didn't matter if I ran the script on the ... WinNT provider only rename domain groups, ...
    (microsoft.public.windows.server.scripting)

Loading