Page 2 of 2 <12
Topic Options
#75969 - 2003-07-22 02:52 PM Re: Error in expression.!
Viggen Offline
Starting to like KiXtart

Registered: 2002-03-22
Posts: 110
Hi!
Sorry I haven't answered earlier, but a big thunderstorm fried my ISPs equipment so I haven't had a stable connection to the Internet since last Friday.

Howard...

Since I'm not to god with Ad I'll try and explain what i'm after.

This is how I have structured my Ad:
 -

I have a script that creates users in Ad, and now I want to ad the users to specific groups in the creation process.

The school and the groups are specified earlier in the script as:
$gg1 =
$gg2 =
$lg =
$sc =
(trying to use the old U.G.L.P system on the groups)
($gg2 is a member of $lg1)

So when the script has created the user it then checks for a group and if the group exist it adds the user
OR
If the group doesn't exit it first creates the group and then adds the user.

Hope that I'm not to unclear here but then again... AD isn't my strong suite.

/V

[edit: Hmmm adding an image doesn't seem to work... Here is an link to the image.]

[ 22. July 2003, 14:58: Message edited by: Viggen ]

Top
#75970 - 2003-07-22 03:33 PM Re: Error in expression.!
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
I can not get to your image as that site is blocked.

Are you using COM [GetObject("LDAP://domainname/distinguished name")] or [GetObject("WinNT://domainname/groupname,group")]?

Please post your code and search the board for examples of LDAP and WinNT usage.

[ 22. July 2003, 15:33: Message edited by: Howard Bullock ]
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#75971 - 2003-07-22 03:56 PM Re: Error in expression.!
Viggen Offline
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

Top
#75972 - 2003-07-22 04:57 PM Re: Error in expression.!
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
I will have some additional time this evening to write some example COM code for you.

binding to an OU
creating a group in that OU
adding a member to the group

Keep posting you progress. If you find some useful examples and have specific question I may be able to respond to them during the day.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#75973 - 2003-07-23 02:28 PM Re: Error in expression.!
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Sorry, had long running program and needed to leave the computer at work. I will try to find time today for writing you some examples.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#75974 - 2003-07-23 03:04 PM Re: Error in expression.!
Viggen Offline
Starting to like KiXtart

Registered: 2002-03-22
Posts: 110
No prob!

I'm grateful for all the help I'm getting, so just take your time.

T.I.A

/V

Top
#75975 - 2003-07-23 05:27 PM Re: Error in expression.!
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
To add a member to the group you can use pre-existing UDFs. Try looking up "GroupAdd"

Here is a function to create an AD group in a specified container. I will be formalizing this and posting it to the UDF Library later today or tomorrow.


Function CreateADGroup ($Container, $GrpName, $GrpType, $SecurityEnabled, optional $Description, optional $sSAMAcctName)

;ADS_GROUP_TYPE_GLOBAL_GROUP = 0x00000002,
;ADS_GROUP_TYPE_DOMAIN_LOCAL_GROUP = 0x00000004,
;ADS_GROUP_TYPE_LOCAL_GROUP = 0x00000004,
;ADS_GROUP_TYPE_UNIVERSAL_GROUP = 0x00000008,
;ADS_GROUP_TYPE_SECURITY_ENABLED = 0x80000000

Dim $oOU, $oNewGrp

Select
Case $GrpType = "local" $GrpType = &00000004
Case $GrpType = "global" $GrpType = &00000002
Case $GrpType = "universal" $GrpType = &00000008
Case 1
;WriteLog2($LogFile, "Function: CreateADGroup - Parameter(GrpType) Error: " + @error + " " + @serror
exit 87
EndSelect
If not ($SecurityEnabled = 1 or $SecurityEnabled = 0)
;WriteLog2($LogFile, "Function: CreateADGroup - Parameter(SecurityEnabled) Error: " + @error + " " + @serror
exit 87
EndIf
If $SecurityEnabled
$GrpType = $GrpType | &80000000
EndIF

If VarTypeName($sSAMAcctName) = "Empty"
$sSAMAcctName = $GrpName
EndIf
If Len($sSAMAcctName) > 20 Then
; "SamAccountName CANNOT be bigger than 20 characters"
$sSAMAcctName = left($sSAMAcctName, 20)
EndIf


$oOU = GetObject("LDAP://" + $Container)
If @error = 0
$oNewGrp = $oOU.Create("group", "CN=" + $GrpName)
$oNewGrp.Put("sAMAccountName", $sSAMAcctName)
$oNewGrp.Put("GroupType", $GrpType)
If VarTypeName($Description) <> "Empty"
$oNewGrp.Put("Description", $Description)
Endif
$oNewGrp.SetInfo
If @error <> 0
;WriteLog2($LogFile, "Function: CreateADGroup - SetInfo Error: " + @error + " " + @serror
exit @error
EndIf
Else
;WriteLog2($LogFile, "Function: CreateADGroup - Get OU Error: " + @error + " " + @serror
exit @error
EndIf
$oOU = 0
$oNewGrp = 0
exit 0


[ 23. July 2003, 17:43: Message edited by: Howard Bullock ]
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#75976 - 2003-07-24 08:44 AM Re: Error in expression.!
Viggen Offline
Starting to like KiXtart

Registered: 2002-03-22
Posts: 110
I bow before you, o mighty AD guru. [Big Grin]

I will try this out and if it works,
(which I have no doubts about)
then I have som minor shelling issuses left to clean up.
(non AD related)

After that I'm runing a "clean" kix-script [Smile]

Thanks again!

/V

Top
#75977 - 2003-07-24 02:04 PM Re: Error in expression.!
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Then are some other pieces of code that may be useful. As you build your script, keep use informed and we can give you some additional ideas.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
Page 2 of 2 <12


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

Who's Online
1 registered (Allen) and 1198 anonymous users online.
Newest Members
M_Moore, BeeEm, min_seow, Audio, Hoschi
17883 Registered Users

Generated in 0.057 seconds in which 0.022 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