Viggen
Starting to like KiXtart
Registered: 2002-03-22
Posts: 110
|
Strange, I can get into it. Let's try this then.
I have a root called schools.mycompany.com under it I have an OU called schools. under that I have a few OUs called "school 1","school 2" and so on. Under them I have 3 OUs. Groups, Students & Teachers.
Posting the code... hmm... 417 lines...
I think i'll put some snippets in instead.
This is what I use to connect with:
code:
$adsDomain = GetObject("LDAP://$ou,$dc") if $adsDomain=0 ? "Kan inte ansluta till servern" ? @SERROR + " (" + @ERROR + ")" quit 1 endif
And here's what I'm using for searching and adding groups:
code:
$cn = $adsUser.sAMAccountname $year = RIGHT(LEFT($cn,4),2) $dn = "OU=$ou2,OU=$ou3,$dc" $temp = @Curdir + "\dsquery.txt" $cmd = "%ComSpec% /C" shell '$cmd dsquery group $dn -scope subtree -name $gg1 -q > $temp' $NUL = OPEN(1,$temp) $dsq = Readline(1) $NUL = CLOSE(1) Del $temp IF NOT INSTR($dsq,$gg1) shell 'dsadd group CN=$gg1,OU=Groups,OU=$ou2,OU=$ou3,$dc -desc "Alla Elever På Skolan" -q' ENDIF shell '$cmd dsquery group $dn -scope subtree -name $lg > $temp' $NUL = OPEN(1,$temp) $dsq = Readline(1) $NUL = CLOSE(1) Del $temp IF NOT INSTR($dsq,$lg) shell 'dsadd group CN=$lg,OU=Groups,OU=$ou2,OU=$ou3,$dc -scope l -desc "Lokal Grupp Med Elever Födda -$year" -q' ENDIF shell '$cmd dsquery group $dn -scope subtree -name $gg2 > $temp' $NUL = OPEN(1,$temp) $dsq = Readline(1) $NUL = CLOSE(1) Del $temp IF NOT INSTR($dsq,$gg2) shell 'dsadd group CN=$gg2,OU=Groups,OU=$ou2,OU=$ou3,$dc -desc "Global Grupp Med Elever Födda -$year" -memberof CN=$lg,OU=Groups,OU=$ou2,OU=$ou3,$dc -q' ENDIF shell "dsmod group CN=$gg1,OU=Groups,OU=$ou2,OU=$ou3,$dc -addmbr CN=$cn,$ou,$dc -q" shell "dsmod group CN=$gg2,OU=Grupper,OU=$ou2,OU=$ou3,$dc -addmbr CN=$cn,$ou,$dc -q"
(note. $ou2 is for example "school 1" and $ou3 is Schools)
Yes, yes... I know I'm shelling out, and it isn't the nicest formating around, but it works and with not to many lines of code.
I'm curently searching the board.
/V
|