|
server
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Script to Rename Computer Name in Domainhi
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 Show quoteHide quote :-)
--
skepper
------------------------------------------------------------------------
skepper's Profile: http://forums.techarena.in/members/73011.htm
View this thread: http://forums.techarena.in/server-scripting/1210050.htmhttp://forums.techarena.in Skepper wrote:
> To rename a computer you bind to the parent OU/Container of the computer > 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 ...) > > 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 "jsm***@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] wrote:
Show quoteHide quote > Skepper wrote: I think a much easier method is to use the Netdom resource kit utility> > > > > 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/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/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 > 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 "jsm***@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 which is easily scripted and can be done remotely. -- skepper wrote:
> i looking a script to rename computer name in domain server 2003 http://www.google.com/search?q=what+is+netdom.exe> > something in VB + MassageBox [Enter New Computer Name] > > include user name + password to change it (domain remember ...) -- Shenan Stanley MS-MVP -- How To Ask Questions The Smart Way http://www.catb.org/~esr/faqs/smart-questions.html
Delete Folders using WMI
Scripting Language DNS suffix search list... Robocopy - not providing destination in log output WMI & Eventlogs auto add sutdents to AD 2008 How to make goto when nowhere to go ? grab a String (server name) from log Stopping Service when Memory reaches 2 GB Send to Compressed Folder missing for limited users on XP Pro |
|||||||||||||||||||||||