Page 1 of 2 12>
Topic Options
#188272 - 2008-06-18 06:17 PM Add Users to Groups Via LDAP provider
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
I have tried several variants on this and can't seem to find the exact syntax needed. I continually get error -2147352567 for both @error printouts. $User is passed earlier in the code I know that it is getting translated correctly.

Using KiX 4.60
Windows Server 2003 SP2
KiXForms .Net


Version 1
 Code:
$WS = GetObject("LDAP://CN=UPM_Test,OU=Login Script,OU=!Development,DC=MyDomain,DC=SubDomain,DC=SubDomain2,DC=TopLevel")
$Nul = TranslateName(3,"",3,@domain+"\"+$User,1)[0] 
$WS.add ($nul.ADsPath)
@ERROR + @SERROR + @CRLF
$WS.Setinfo
@ERROR + @SERROR 


Version 2
 Code:
$WS = GetObject("LDAP://CN=UPM_Test,OU=Login Script,OU=!Development,DC=MyDomain,DC=subdomain,DC=subdomain2,DC=toplevel")
$Nul = TranslateName(3,"",3,@domain+"\"+$User,1)[0] 
$WS.PutEx (3,"member",$Nul)
$WS.Setinfo




Edited by Gargoyle (2008-06-18 06:18 PM)
Edit Reason: took out some long lines
_________________________
Today is the tomorrow you worried about yesterday.

Top
#188277 - 2008-06-18 11:18 PM Re: Add Users to Groups Via LDAP provider [Re: Gargoyle]
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
I think I remember seeing a post or two from Shawn saying that there are COM issuses with 4.60.. Can you try 4.53?

Thanks,

Kent
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#188278 - 2008-06-18 11:47 PM Re: Add Users to Groups Via LDAP provider [Re: Gargoyle]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4548
Loc: USA
I've not done this so this may be off base, but doesn't the group and the user have to be an object? Maybe this will work?

 Code:
$WS = GetObject("LDAP://CN=UPM_Test,OU=Login Script,OU=!Development,DC=MyDomain,DC=SubDomain,DC=SubDomain2,DC=TopLevel")
$User =Getobject(TranslateName(3,"",3,@domain+"\"+$User,1)[0])
$WS.add ($User.ADsPath)
@ERROR + @SERROR + @CRLF
$WS.Setinfo
@ERROR + @SERROR 


I don't know what Translatename returns, so its possible you will need something like $User=getobject("LDAP://" + TranslateName... )

Top
#188279 - 2008-06-19 12:38 AM Re: Add Users to Groups Via LDAP provider [Re: Gargoyle]
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11624
Loc: CA
Not sure that you need translate name do you?

Here is the Microsoft VB rendition of it. I went and looked and I don't currently have any KiX code for it either. I've always used the WinNT for most user/group management.

 Code:
Set objOU = GetObject("LDAP://OU=Management,dc=fabrikam,dc=com")
Set objGroup = objOU.Create("Group", "cn=atl-users")
objGroup.Put "sAMAccountName", "atl-users"
objGroup.SetInfo
 
objGroup.Add objUser.ADSPath


Top
#188280 - 2008-06-19 12:44 AM Re: Add Users to Groups Via LDAP provider [Re: NTDOC]
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11624
Loc: CA
Or perhaps this link
Add a User to Two Security Groups

Top
#188281 - 2008-06-19 01:19 AM Re: Add Users to Groups Via LDAP provider [Re: NTDOC]
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
@ Doc,
As to the link you provided, that is what I started with, and what lead to the second version. However if you could give me an example with WinNT I am open to using it as well, just everything that I found had to do with LDAP.

@ Allen / Kyder - I will try those solutions and see what happens. I will update probably tomorrow.
_________________________
Today is the tomorrow you worried about yesterday.

Top
#188282 - 2008-06-19 02:20 AM Re: Add Users to Groups Via LDAP provider [Re: Gargoyle]
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
4.53 Did not make a diffence. Declaring both as Objects worked for the ADD, but what is the command for delete.

WS.ADD - This worked as expected
WS.Delete - Not so well same error as before. I am sure it is just me.
_________________________
Today is the tomorrow you worried about yesterday.

Top
#188283 - 2008-06-19 02:43 AM Re: Add Users to Groups Via LDAP provider [Re: Gargoyle]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4548
Loc: USA
See
How Can I Remove Group Members Whose User Accounts Reside in a Specific OU?
http://www.microsoft.com/technet/scriptcenter/resources/qanda/jan08/hey0102.mspx

Below is probably the important part... just not sure how the user/array part would go without some testing

 Code:
$ADS_PROPERTY_DELETE=4
$objGroup.PutEx $ADS_PROPERTY_DELETE, "member", array(strUser) 
$objGroup.SetInfo 


Top
#188284 - 2008-06-19 04:01 AM Re: Add Users to Groups Via LDAP provider [Re: Allen]
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
Allen as you can tell I tried that with Version 2 of my code (exchange the 3 and 4) I got the syntax from other examples I found here.

Who knows....
_________________________
Today is the tomorrow you worried about yesterday.

Top
#188286 - 2008-06-19 11:04 AM Re: Add Users to Groups Via LDAP provider [Re: Gargoyle]
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11624
Loc: CA
Can't promise, but if I get some time tomorrow I'll try and see if I can get it to work Garg.
Top
#188287 - 2008-06-19 02:38 PM Re: Add Users to Groups Via LDAP provider [Re: NTDOC]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4548
Loc: USA
Garg, so what did the final "add" code look like?
Top
#188288 - 2008-06-19 04:32 PM Re: Add Users to Groups Via LDAP provider [Re: Allen]
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
Here is the entire snippet

 Code:
If $Checks[2] = -1
;VPN ADD
	$Nul = WriteLine($FH,"Function Requested = VPN ADD"+@CRLF)
	UpdateProgress(25)
	$Label3.Text = "Adding VPN - Telecommute to user "+$User
	$WS = GetObject("LDAP://CN=UPM_Test,OU=Login Script,OU=!Development,DC=Fabrikom,DC=Microsoft,DC=Com")
	$Usr = GetObject("LDAP://"+ TranslateName(3,"",3,@domain+"\"+$User,1)[0])
	$WS.add ($Usr.ADsPath)
	$WS.Setinfo
        If @Error = 0
	     $Nul = WriteLine($FH,"Added user "+$user+" to TermTelecom "+@Date+"-"+@Time+@CRLF)
        Else
             $Label3.Text = "Add User failed, please open a ticket!"
        EndIf
	ClearForm()
EndIf


Just have to get the delete to work now. \:\)
_________________________
Today is the tomorrow you worried about yesterday.

Top
#188306 - 2008-06-20 05:49 PM Re: Add Users to Groups Via LDAP provider [Re: Gargoyle]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4548
Loc: USA
I havent tried the following code, but based on the examples from MS and that the vbscript array() is nothing more than split(), maybe this will work.

 Code:
dim $usr[0]
$WS = GetObject("LDAP://CN=UPM_Test,OU=Login Script,OU=!Development,DC=MyDomain,DC=subdomain,DC=subdomain2,DC=toplevel")
$usr[0] = TranslateName(3,"",3,@domain+"\"+$User,1)[0] 
$WS.PutEx (4,"member",$usr)
$WS.Setinfo


Edited by Allen (2008-06-25 07:28 AM)

Top
#188315 - 2008-06-21 08:23 AM Re: Add Users to Groups Via LDAP provider [Re: Allen]
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
Thanks Allen, I will look into this on Monday.
_________________________
Today is the tomorrow you worried about yesterday.

Top
#188343 - 2008-06-25 07:26 AM Re: Add Users to Groups Via LDAP provider [Re: Gargoyle]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4548
Loc: USA
Hey Garg, I just finished working on a couple of UDFs and I'm pretty sure the code I posted previously was wrong on the split. So... I updated my code above to what I think will work. Let me know.
Top
#188344 - 2008-06-25 08:00 AM Re: Add Users to Groups Via LDAP provider [Re: Allen]
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
Thanks Allen, haven't had a chance to get back to this as of yet. So many projects, so little people to work on them.
_________________________
Today is the tomorrow you worried about yesterday.

Top
#188392 - 2008-06-26 04:39 PM Re: Add Users to Groups Via LDAP provider [Re: Gargoyle]
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
Allen,
I am very happy to report that did the trick. So the big change was to convert the $usr to an Array? I appreciate all the help. Now on to more added features for this.
_________________________
Today is the tomorrow you worried about yesterday.

Top
#188400 - 2008-06-26 06:11 PM Re: Add Users to Groups Via LDAP provider [Re: Gargoyle]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4548
Loc: USA
Cool... I learned quite a bit about LDAP between your's and Mart's requests this week. Thanks.
Top
#188416 - 2008-06-27 04:08 AM Re: Add Users to Groups Via LDAP provider [Re: Allen]
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
When I get done with this script I am going to attempt the clean up / sanitization of it and will post it here for those that want to play with some of the same features.

Once I have the GUI flushed out I will post it so everone gets the idea of what I have done as well. But it is a ways off as it is project 12 of 32 that I am assigned to right now.
_________________________
Today is the tomorrow you worried about yesterday.

Top
#188422 - 2008-06-27 01:52 PM Re: Add Users to Groups Via LDAP provider [Re: Gargoyle]
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1895
Loc: Hilversum, The Netherlands
I know I am late to react but this I used for the longest time and always works (2000,2003 and even in 2008)
 Code:
$WS = GetObject("LDAP://CN=UPM_Test,OU=Login Script,OU=!Development,DC=MyDomain,DC=SubDomain,DC=SubDomain2,DC=TopLevel")
$Nul = TranslateName(3,"",3,@domain+"\"+$User,1)
$Nul = GetObject("LDAP://"+$Nul[0])
$WS.Add($nul.ADsPath)
@ERROR + @SERROR + @CRLF
$WS.Setinfo
@ERROR + @SERROR

Top
Page 1 of 2 12>


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

Who's Online
1 registered (Allen) and 286 anonymous users online.
Newest Members
Timothy, Jojo67, MaikSimon, kvn317, kixtarts2025
17874 Registered Users

Generated in 0.075 seconds in which 0.026 seconds were spent on a total of 14 queries. Zlib compression enabled.

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