WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

ADSI
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Adding a Workstation to AD in Correct OU

 Keywords:  ADSI Active Directory Add Workstation NT4 W2K

Question:

I need to add WinXP OS machines to AD on a regular basis. Rather than add them by default into the 'computer container' and then move them to their final destination, thought it would be nice if this could be done all at once.

Searching the Tech Database, I found: ' Adding a Workstation (NT4 and W2K) to the Domain and Specify Correct OU'

which appears to be the perfect answer to our needs. However I cannot successfully run the code without generating an error.

My basic question is:

Has anyone got this particular piece of code to work'? If so where I am going wrong. Trouble is, I am not an expert in AD or it's properties/concepts and so am a bit clueless where to go next.

When I run the code (with necessary modifications for our environment), I always obtain an error in the 4th line from the end i.e.

dsSetProperty (sComputerPath, "ntsecurityDescriptor", secDescriptor)
this yields the error:
Wil Extender Error: 1026:ADSI error.
The security ID structure is invalid
WINBATCH 32 2002H
WIL VERSION 3.8hch
As said haven't a clue why above is happening...

Answer:

The reason for this is that the script was never meant to be used to JOIN a machine to a domain. You can't actually run it successfully from a non-trusted machine or you get this error. It was made to ADD machine accounts to a domain using a trusted machine (an administrative task for some folks...). The major difference is similar to the difference between using NetDom ADD vs NETDOM JOIN. (netdom 2000).

User Shared code:

This is a script I created. It works well in our environment. Replace the XX's and the YOUR info
AddExtender("wwads34I.dll")

i_errorlevel=1
what=param1
s_pcname = Environment ("computername")
s_country=strsub(s_pcname,3,2)
s_machine=strsub(s_pcname,5,1)
s_temp="c:\windows\temp"
s_administrator="YOURADMIN"
s_domain="YOURDOMAIN"
s_password="YOURPASSWORD"

if strupper(s_machine) == "L" then
s_machine="Laptops"
else
if strupper(s_machine) == "D" then
s_machine = "Desktops"
end if
end if

if strupper(s_country) == "BE" then
country = "Belgium"
dc="WELEUDC2"
else
if strupper(s_country) == "FR" then
country = "France"
dc="WEARMDC2"
else
if strupper(s_country)=="LU" then
country = "Luxembourg"
dc="WEDIEDC2"
else
if strupper(s_country) == "NL" then
country = "Netherlands"
dc="WEBREDC2"
else
i_errorlevel=99
goto EndScript
end if
end if
end if
end if

OU="OU=%s_machine%,OU=Workstations,OU=%country%,DC=XX,DC=XX,DC=XX"
td=TimeDate()

if strlower(What)=="join" then
dsSetCredent("%s_domain%\%s_administrator%", "%s_password%")
sAdsiPath = "LDAP://%dc%.YOURDOMAIN"
lPaths= dsFindPath(sAdsiPath, "cn=%s_pcname%")
logfile=fileopen ("c:\rollout\JoinDOM.LOG","WRITE")
if lpaths <> "" then FileWrite (logfile, "%lpaths% deleted in AD")
dsDeleteObj(lPaths)
timedelay(5)
end if
runshell("netdom.exe","JOIN %s_pcname% /domain:YOURDOMAIN\%dc% /userD:%s_domain%\%s_administrator% /passwordD:%s_password% /OU:%ou%","",@HIDDEN,@WAIT)
status=IntControl (64, 0, 0, 0, 0)
if status <> 0 then
FileWrite (logfile, " !ERROR! NETDOM JOIN ERROR %status% on %td%")
i_errorlevel=99
else
handle=fileopen("c:\temp\joindom.cfg","WRITE")
fileclose(handle)
FileWrite (logfile, "NETDOM JOIN completed on %td%")
i_errorlevel=0
end if
fileclose(logfile)
end if
else
if strlower(What)=="verify" then
runshell("netdom.exe","VERIFY %s_pcname% /domain:YOURDOMAIN","",@HIDDEN,@WAIT)
status=IntControl (64, 0, 0, 0, 0)
message("VERIFY Status",status)
end if
end if

:EndScript
IntControl (1000, i_errorlevel, 0, 0, 0)
exit 

Article ID:   W15377
File Created: 2014:07:18:09:38:24
Last Updated: 2014:07:18:09:38:24