Results 1 to 4 of 4

Thread: Script to Rename Computer Name in Domain

  1. #1
    Join Date
    Jan 2009
    Posts
    3

    Script to Rename Computer Name in Domain

    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

    :-)

  2. #2
    Richard Mueller [MVP] Guest

    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/scr.../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/scr.../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@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/scr..._wmi_ciga.mspx

    --
    Richard Mueller
    MVP Directory Services
    Hilltop Lab -
    --

  3. #3
    Mark D. MacLachlan Guest

    Re: Script to Rename Computer Name in Domain

    Richard Mueller [MVP] wrote:

    > 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/scr.../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
    > link:
    >
    > http://www.microsoft.com/technet/scr.../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
    > 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@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/scr..._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.

    --


  4. #4
    Shenan Stanley Guest

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


    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



Similar Threads

  1. Replies: 3
    Last Post: 17-01-2014, 10:02 AM
  2. Need vbs script to add computer in the domain (OU )
    By lolo1790 in forum Windows Server Help
    Replies: 10
    Last Post: 04-03-2011, 05:50 AM
  3. Rename Domain Controller
    By aileen in forum Active Directory
    Replies: 5
    Last Post: 19-01-2011, 01:49 AM
  4. Remotely rename computer and join to domain
    By maketu in forum Windows Security
    Replies: 2
    Last Post: 16-07-2009, 06:40 AM
  5. Interactive Rename and Domain Join Script Needed
    By sc in forum Windows Server Help
    Replies: 3
    Last Post: 28-12-2008, 04:08 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,653,079,482.46561 seconds with 17 queries