dbustamante
IS-IT--Management
I have alot of pc's i have to re-image and im trying to come out with a script or bat file to join a new pc to my domain. but im not having any luck here is what i have so far but its missing something. any ideas?
Code:
cmd /c netdom join %COMPUTERNAME% /domain:%JoinDomain% /userd:%DMID% /passwordd:%DMPW% /ou:%OU_String%,DC=%DC1%,DC=%DC2%,DC=%DC3%
IF %ErrorLevel% EQU 0 (
ECHO ***%~n0 Returned ErrorLevel - %ErrorLevel% >>%Logfile%
ECHO ***%~n0 Successfully joined %Computername% to %JoinWorkGroup% >>%Logfile%
echo Successfully joined %Computername% to %JoinWorkGroup%
GOTO :CmpltJn
)
IF %ErrorLevel% EQU 2224 (
ECHO ***%~n0 Returned ErrorLevel - %ErrorLevel% >>%Logfile%
GOTO :TakeOvr
)
ECHO ***%~n0 Returned ErrorLevel - %ErrorLevel% >>%Logfile%
REM --- Failed to join domain
GOTO :ErrorHandler
:TakeOvr
cmd /c netdom join %COMPUTERNAME% /domain:%JoinDomain% /userd:%DMID% /passwordd:%DMPW%
IF ErrorLevel 1 (
ECHO ***%~n0 Returned ErrorLevel - %ErrorLevel% >>%Logfile%
REM --- Failed to join domain
GOTO :ErrorHandler
)
IF %ErrorLevel% EQU 0 ECHO ***%~n0 Returned ErrorLevel - %ErrorLevel% >>%Logfile%
REM --- Moves object to specified OU. Ensures object is in correct location. Shorter than testing and then moving is simply moving.
cmd /c dsquery computer domainroot -d %JoinDomain% -name %ComputerName%|dsmove -newparent "%OU_String%,DC=%DC1%,DC=%DC2%,DC=%DC3%" -U %DMID% -P %DMPW%
IF ErrorLevel 1 (
ECHO ***%~n0 Returned ErrorLevel - %ErrorLevel% >>%Logfile%
REM --- Failed to move to correct OU
GOTO :ErrorHandler
)
IF %ErrorLevel% EQU 0 ECHO ***%~n0 Returned ErrorLevel - %ErrorLevel% >>%Logfile%
:CmpltJn