I have 30 machines that need to be unjoined from a domain. I am rebuilding a server and I do not want it to run through a login. After the server is rebuilt, i need to join the machines back to the domain. Can I do this with kixtart?
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
You can use the command line "netdom" to join a computer to a domain either locally on the computer or remotely.
You may specify the OU that you want to create the computer account in. If the computer account already exists in the domain then you must specify the same OU, otherwise you will get an "account already exists" error.
#157970 - 2006-02-2808:03 PMRe: UnJoin 20 Computers From Domain then Rejoin
NTDOCNTDOC Administrator
Registered: 2000-07-28
Posts: 11625
Loc: CA
with a FOR EACH or similar looping structure.
Richard: As for the join thing in the same OU issue I think you can do a MOVE to get around this behavior (but can't currently test this so speaking from 2 year or older memory)
all I know is that (netdom join \/domain:/userd:/passwordd:* /userO:/passwordO:*)
adds the computer to the domain. where would I place the "for each" statement.
2. I also looked at a program you created for kixforms called Join AD v.1.0, I registered the .dll and ran the script but it did not work. I ran it from my c: and in there i had the netdom,kix32, and the joinad.kix script. Something about line 37
anyway, if the for each statement works i will just try that for now and then try to figure out the other later.
#157972 - 2006-02-2808:56 PMRe: UnJoin 20 Computers From Domain then Rejoin
NTDOCNTDOC Administrator
Registered: 2000-07-28
Posts: 11625
Loc: CA
Well nice that you found the search engine (better than a lot of noobs).
Well you can't just use my script as is since it was designed for my AD. You would need to know enough about scripting to change certain fields for your use.
That was a really old script before Chris and other wrote some better routines.
I'll show you an example in a litlle while. Have some other work to do right now.
1st and foremost, thanks for you quick responses. It has been about 2 weeks of me trying to dab at this and to no victory.
Good News: In the begining I copied the script, it was not running at all, I then looked at my "Scripting with Kixtart" book and noticed that the %compspec needed an extra % at the end of it. once I did this I was able to start the netdom cmd. BAD NEWS Below is your script with my added netdom cmds: I know the netdom script is running b/c I placed an * for the pwds and after I enter them it says "Network Path could not be found" The command failed to complete successfully. I verified the computers.txt and the machine is in there just like you said "pcname" w/o the "". Its all in the same directory. Just to make sure it wasn't my netdom command that wasn't working, I went ahead and ran the netdom command manually from the server, and forced 1 of my client pc's to be removed from the domain. I then re-added it with the netdom command again. I have tested the netdom cmds exactly like you see above in the script and it works when I run it manually, but when I attempt to run it through kix it does not work.
Any Ideas?
Break On Dim $SO $SO=SetOption('Explicit','On') $SO=SetOption('NoVarsInStrings','On') $SO=SetOption('NoMacrosInStrings','On')
Dim $List,$Computer,$Computers $List = @ScriptDir+'\'+'computers.txt' $Computers = ReadFile($List) For Each $Computer In $Computers IF $Computer SHELL '%comspec% /c NETDOM Join $Computer /domain:testing /userd:administrator /passwordd:* /userO:administrator /passwordO:*' ;instead of example above you would put in something like this
EndIf Next
Function ReadFile($file) Dim $lf, $f, $_, $t $lf=CHR(10) $f=FreeFileHandle $_=Open($f,$file) If @ERROR Exit @ERROR EndIf Do $t=$t+$lf+ReadLine($f) Until @ERROR $_=Close($f) $ReadFile=Split(SubStr($t,2),$lf) EndFunction
If you don't know why this is the case then check the manual for what SetOption() does. If you are still unsure after that then ask again, as it is an important point.
You guys are amazing, I added the code that Richard posted and it worked. I was able to remove the machine from the domain. The only problem I'm having now is that everytime that I attempt to join the machine to the domain, I get the following error: Login Failure:Unknown user name or bad password The command failed to complete successfully.....
I have been joining and removing this same pc from the domain a couple of times in the week by just using the netdom cmd and I don't know if this could have somehow messed it up. The weird thing is that it works only when I remove the machine from the domain.
Anyway, Thanks again for all of your help. Keep an eye out for my posts
FYI! The solution to why my client pc was not able to join the domain after I removed it via the kix script, was because for some reason the following registry key was being set to 1 instead of zero: