Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to join new pc to domain 3

Status
Not open for further replies.

dbustamante

IS-IT--Management
Jul 12, 2010
63
US
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
 
as tsuji says, DC=LOCAL, and as you say this can be seen from the userdnslocal, seperated with a .

I Hear, I Forget
I See, I Remember
I Do, I Understand

Ronald McDonald
 
ok i added LOCAL to the second DC= and it gave the same results it just gave the

Code:
C:\Documents and Settings\Administrator>Desktop\joindomain.vbs /domaIn:RGDCDOMAIN /username:RGDCDOMAIN\dbustamante /password:Rgdcmis76 /ou:"OU=DEV,OU=RGDCcomputers,DC=RGDCDOMAIN,DC=LOCAL" /deleteaccount:false
Microsoft <R> Windows Script Host Verson 5.7
Copyright <C> Microsoft Corporation. All Rights Reserved.

OU=DEV,OU=RGDCcomputrees,DC=RGDCDOMAIN,DC=LOCAL

C:\Documents and Settings\Administator>

im still getting an error code 333 but i can add a pc to the domain with the same credentials that i entered in the parameters. so i checked the adsiedit.msc and the information is correct.

Code:
USERDNSDOMAIN=RGDCDOMAIN.LOCAL
USERDOMAIN=RGDCDOMAIN
USERNAME=dbustamante
 
hi dbustamante, i can assure you there is nothing wrong with the code, however, can you edit these lines? note, On Error Resume Next has been commented out. This should give you a run time, it may be of interested as to what the error is

'does out target OU exist
Dim objTargetOU, adsNameSpace, strTemp
Set adsNameSpace = GetObject("LDAP:")
'On Error Resume Next
Set objTargetOU = adsNamespace.OpenDSObject("LDAP://" & strDomain & ":389/" & strOU, strUsername, strPassword, 1)
strTemp = objTargetOU.name
On Error GoTo 0
If strTemp = "" Then
intReturn = 333
Exit Sub
End If


I Hear, I Forget
I See, I Remember
I Do, I Understand

Ronald McDonald
 
dbustamantle, do you really have an OU called DEV contained in the RGDComputers ou? e.g. your command parameter for the OU is OU=DEV,OU=RGDCcomputers.
adsiedit.msc, you can use this tool to right click the container and have a look at its properties, its ADsPath property will show you the string you should be putting in the parameter

I Hear, I Forget
I See, I Remember
I Do, I Understand

Ronald McDonald
 
@op:
You can make abstraction of the exact adspath for security reason or whatever. But, you have to show the faithful representation with the crucial structure of it if you want to ask for help in that regard. If crucial structure is abstracted out, people cannot help and will constantly be misled.

In the original bat, you have
>ou:%OU_String%,DC=%DC1%,DC=%DC2%,DC=%DC3%
with three level of DC. And now, suddenly, all become problematic. Local appeared in mrmovie's original script as demo sample in the comment. You don't necessary have that name. It is your exact ad structure that matters.

Can we suppose you have good knowledge of the adspath to the ou where you want to put the account in? Why there are such difficulty to come up with the adspath to the ou?
 
>[tt][mrmovie said] sorry Gents, i thought by posting a 'working' example it would save a lot of time.[/tt]
Got to come to the conclusion that that would _not_ necessarily save a lot of time and that is conditional very much on the contingent factor of the recipients being prepared for it or not. All in all, a nearly heroic effort! Well done and have a well deserved star on me, mrmovie!
 
tsuji if I could give more than 1 star per user instead of just per post you and mrmovie would be at the top of the leader boards every month I do appreciate all the help from both of you this is going to help out a lot.
 
thanks Tsuji, i think i will avoid posting 'scripts' in the future :). a worth while exercise though, gave me a chance to look at the script (for the first time in years), it could definitely do with a little tidy up.

dbustamantle, thanks for the feedback

I Hear, I Forget
I See, I Remember
I Do, I Understand

Ronald McDonald
 
well i am glad to say that i was able to get the script working after mrmovie asked about the OU=DEV so i checked it out and i dont have a DEV or so this is what i came up with

Code:
Desktop\joindomain.vbs /domaIn:RGDCDOMAIN /username:RGDCDOMAIN\dbustamante /password:Rgdcmis76 /ou:"OU=RGDCcomputers,DC=RGDCDOMAIN,DC=LOCAL" /deleteaccount:false

and it worked like a charm. Thank both of you for all your help. you dont know how much easier this is going to make my job.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top