Discussion:
Script to Rename Computer Name in Domain
(too old to reply)
skepper
2009-07-08 11:12:45 UTC
Permalink
hi

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



TNX

Skepper

:-)
--
skepper
------------------------------------------------------------------------
skepper's Profile: http://forums.techarena.in/members/73011.htm
View this thread: http://forums.techarena.in/server-scripting/1210050.htm

http://forums.techarena.in
Richard Mueller [MVP]
2009-07-08 15:31:28 UTC
Permalink
Post by skepper
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 "***@MyDomain.com".

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
--
Mark D. MacLachlan
2009-07-08 19:16:06 UTC
Permalink
Post by Richard Mueller [MVP]
Post by skepper
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
http://www.microsoft.com/technet/scriptcenter/scripts/ad/computer/cptr
vb13.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
http://www.microsoft.com/technet/scriptcenter/scripts/ad/computer/cptr
vb14.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
========== 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
If you want to change the NetBIOS name of the computer (per the
second link above) using WMI, you would provide alternate credentials
http://www.microsoft.com/technet/scriptcenter/guide/sas_wmi_ciga.mspx
I think a much easier method is to use the Netdom resource kit utility
which is easily scripted and can be done remotely.

--
Shenan Stanley
2009-07-10 04:35:44 UTC
Permalink
Post by skepper
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 ...)
http://www.google.com/search?q=what+is+netdom.exe
--
Shenan Stanley
MS-MVP
--
How To Ask Questions The Smart Way
http://www.catb.org/~esr/faqs/smart-questions.html
Loading...