sedberg1
asked on
Script to rename a member server for Windows Server 2008 R2
I have a server that's a part of a workgroup. I need to join it to a domain and rename it. Preferably, both would happen at the same time. The script I was using was:
REM Asks for computer name and domain name
SET /P BRANCH_NO="Enter branch number: "
SET /P DOMAINNAME="Enter domain name: "
SET /P USERNAME="Enter domain username: "
SET /P PASSWORD="Enter password: "
REM Joins server to the domain
netdom join /d:%DOMAINNAME% localhost /ud:%DOMAINNAME%\%USERNAME % /pd:%PASSWORD% /force >> c:\domain.txt
REM Renames server to isb-brXXXfs
netdom renamecomputer localhost /newname:isb-br%BRANCH_NO% fs /userd:administrator >> c:\domain.txt
The first part joins the domain but the command requires someone to enter Y or N. I tried /force but that doesn't work. Also tried putting a Y in at the end of the domain command but then I get an error. Any suggestions?
REM Asks for computer name and domain name
SET /P BRANCH_NO="Enter branch number: "
SET /P DOMAINNAME="Enter domain name: "
SET /P USERNAME="Enter domain username: "
SET /P PASSWORD="Enter password: "
REM Joins server to the domain
netdom join /d:%DOMAINNAME% localhost /ud:%DOMAINNAME%\%USERNAME
REM Renames server to isb-brXXXfs
netdom renamecomputer localhost /newname:isb-br%BRANCH_NO%
The first part joins the domain but the command requires someone to enter Y or N. I tried /force but that doesn't work. Also tried putting a Y in at the end of the domain command but then I get an error. Any suggestions?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Thanks for the accept. Did this work correctly for you?
ASKER
REM Asks for computer name and domain name
SET /P BRANCH_NO="Enter branch number: "
SET /P DOMAINNAME="Enter domain name including TLD: "
SET /P USERNAME="Enter domain username in format domain\administrator: "
SET /P PASSWORD="Enter password: "
REM Joins server to the domain
netdom join localhost /Domain:%DOMAINNAME% /UserD:%USERNAME% /PasswordD:%PASSWORD% >> c:\domain.txt
REM Renames server to isb-brXXXfs
netdom renamecomputer localhost /NewName:isb-br%BRANCH_NO%
REM Reboots the server to make the changes permanent.
shutdown -r -t 05 -c "System rebooting in 5 seconds"
But the problem is that whenever I run the second part of the script, I get the following error. This is because obviously the computer account in AD already exists. How can I run this script so it overwrites the existing computer account? The thing is, this script will be run during a multi-server deployment, and the names will be created in AD already for later easier management.
The account already exists.
The command failed to complete successfully.