Page 1 of 1 1
Topic Options
#157966 - 2006-02-28 05:05 PM UnJoin 20 Computers From Domain then Rejoin
Dmartin05 Offline
Fresh Scripter

Registered: 2006-02-01
Posts: 49
Hello,

I am trying to see if this is possible:

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?

Top
#157967 - 2006-02-28 05:09 PM Re: UnJoin 20 Computers From Domain then Rejoin
Richard H. Administrator Offline
Administrator
*****

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.

Top
#157968 - 2006-02-28 05:24 PM Re: UnJoin 20 Computers From Domain then Rejoin
Dmartin05 Offline
Fresh Scripter

Registered: 2006-02-01
Posts: 49
I had looked into this and I got it working, but it only works for 1 machine at a time.

Or

If it does work for multiple machines, how do i get it working?

Thanks again for your quick response

Top
#157969 - 2006-02-28 07:06 PM Re: UnJoin 20 Computers From Domain then Rejoin
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
Joindomain and netdom must be run client side
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#157970 - 2006-02-28 08:03 PM Re: UnJoin 20 Computers From Domain then Rejoin
NTDOC Administrator Offline
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)
 

Top
#157971 - 2006-02-28 08:37 PM Re: UnJoin 20 Computers From Domain then Rejoin
Dmartin05 Offline
Fresh Scripter

Registered: 2006-02-01
Posts: 49
NTDOC 2 things,

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.

Top
#157972 - 2006-02-28 08:56 PM Re: UnJoin 20 Computers From Domain then Rejoin
NTDOC Administrator Offline
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.

Top
#157973 - 2006-03-01 03:32 AM Re: UnJoin 20 Computers From Domain then Rejoin
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11625
Loc: CA
Okay, got a few minutes. Let me see if I can whip up an example for you.

BRB

Top
#157974 - 2006-03-01 03:38 AM Re: UnJoin 20 Computers From Domain then Rejoin
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11625
Loc: CA
Okay, here is an example


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
'Computer name: ' + $Computer ?
;instead of example above you would put in something like this
;SHELL '%comspec /c NETDOM <commands you need> '
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

Top
#157975 - 2006-03-01 03:40 AM Re: UnJoin 20 Computers From Domain then Rejoin
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11625
Loc: CA
Try running the script as it is with a file in the same folder as the script called COMPUTERS.TXT

Inside that file you should have a list of computer names to use.

COMPUTER01
COMPUTER02
COMPUTER03
COMPUTER04
COMPUTER05


ETC....


Then when you see and get that going you would use the $Computer for the name of the computer name to run the NETDOM command against.

If you need further explanation or example let us know.

Top
#157976 - 2006-03-01 05:06 AM Re: UnJoin 20 Computers From Domain then Rejoin
Dmartin05 Offline
Fresh Scripter

Registered: 2006-02-01
Posts: 49
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

Top
#157977 - 2006-03-01 05:15 AM Re: UnJoin 20 Computers From Domain then Rejoin
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
You have:
$SO=SetOption('NoVarsInStrings','On')
That means you CANNOT have vars in strings.
You have a var in your string.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#157978 - 2006-03-01 10:23 AM Re: UnJoin 20 Computers From Domain then Rejoin
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
What Les means is that this line:
Code:
SHELL '%comspec% /c NETDOM Join $Computer /domain:testing /userd:administrator /passwordd:* /userO:administrator /passwordO:*' 



Should look more like this:
Code:
SHELL '"'+%COMSPEC%+'" /c NETDOM Join '+$Computer+' /domain:testing /userd:administrator /passwordd:* /userO:administrator /passwordO:*' 



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.

Top
#157979 - 2006-03-01 06:16 PM Re: UnJoin 20 Computers From Domain then Rejoin
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11625
Loc: CA
sorry for missing the extra % but was typing it and never ran it.

Adjust your code per suggestion by Richard and let us know how it goes.

Top
#157980 - 2006-03-02 08:23 AM Re: UnJoin 20 Computers From Domain then Rejoin
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11625
Loc: CA
So Derwin, did you get this working okay?
Top
#157981 - 2006-03-02 03:07 PM Re: UnJoin 20 Computers From Domain then Rejoin
Dmartin05 Offline
Fresh Scripter

Registered: 2006-02-01
Posts: 49
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

DMartin

Top
#157982 - 2006-03-02 09:47 PM Re: UnJoin 20 Computers From Domain then Rejoin
Dmartin05 Offline
Fresh Scripter

Registered: 2006-02-01
Posts: 49
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:

HKLM\System\CurrentControlSet\control\LSA ForceGuest

I will start up another post where I will be asking a question on how I can fix this via script up boot up after joining the domain.......

Top
#157983 - 2006-03-02 09:49 PM Re: UnJoin 20 Computers From Domain then Rejoin
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11625
Loc: CA
Good to hear you got it working. Thanks for replying back.
Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 194 anonymous users online.
Newest Members
BeeEm, min_seow, Audio, Hoschi, Comet
17882 Registered Users

Generated in 0.307 seconds in which 0.195 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org