All Forums >> [Scripting] >> WSH & Client Side VBScript >> VB Script to change computer names and AD computer account remotely Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Hello to all. Let me first start by saying that by no means am I a script writer. What I am looking from someone is a script where I can change the computer name and the computer account for Active Directory network. Maybe, pull the computer names that needs to be changed from an excel file. We have about 200 workstations and we would like to make all the computer names comply with the company standard. I don't want to manually connect to the workstation through VNC, log in, change the computer name and then reboot. Once that is done, then go to ADUC and change the computer account name as well.
I'm not aware of any vbscript-commands which can do what you ask for. One of the tools you can use instead is NETDOM (latest version comes with Windows Server 2003 Resource Kit).
If you use "NETDOM RENAMECOMPUTER ...." you will rename both the computer and the computeraccount in AD.
Here is a script i used for doing what you want. The script do use the netdom.exe so you will need that. It was part of a bigger script so i have removed some stuff so the following script is untested. hopefully i havnt removed anything important. :D You will have to edit <domain> in the RenameComp function to whatever your domain is called. Just search for <domain> and put your own there (without the <>).
Excuse the formating, my original formating seems to be lost when i pasted it in here. Hope it helps!
/CM
< Message edited by crazymatt -- 2/21/2006 11:32:15 PM >
_____________________________
-There is only 10 sorts of people, those who understand binary and those who dont.
Yeah I don't know what it is about this board, but formatting just doesn't seem to work for some people and works just fine for others. Here is crazymatt's code with formatting (I am one of the lucky ones):
Posts: 45
Score: 0
Joined: 2/23/2005
From: USA
Status: offline
I have been tooling around with this script and don't get why I get errors on each line that contains: "<span class="high">computer</span>" Each time I run the script there is an error telling me Error: expected ")" Code: 800A03EE
I must not be understanding the instructions very well. Can someone enlighten me? Please!
Posts: 45
Score: 0
Joined: 2/23/2005
From: USA
Status: offline
Well this script is now officially tested and verified non functional.
1. Script creates both failure.txt and success.txt files at the same time. <-can't tell if it is supposed to create both, but if so, this makes no sense to me. 2. Does not create changename.xls - Not even sure if it is supposed to create the excel file. <-have modified my test script to create the spreadsheet 3. Unsure what objTextFile is equal too, so that errors when debugging. 4. At no time does it prompt for a new computer name, nor does it use a name that I manually placed in col 2 of changename.xls. In fact the spreadsheet is not being written to at all after it is created. I can correct this but always have problems with Dictionary objects.
crazymatt, could you post all of the code this was taken from, so I can figure out where I am going wrong when I attempt to fix this?
It is hard to believe renaming a domain PC could be so darn hard to do with a script.