?
Solved

Visual basic scripting question

Posted on 2006-04-26
3
Medium Priority
?
217 Views
Last Modified: 2012-08-14
Hi all
I am trying to write a new script that gets a group in AD and add one member(domain user) to that group. I have a list 150 user group and members that need to be added in a comma delimited text file. Here is the script that I am using right now :

******************************************************************************************
Const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile ("c:\temp\studentmembers.csv", ForReading)
 
Const ADS_PROPERTY_APPEND = 3
Do Until objTextFile.AtEndOfStream
    strNextLine = objTextFile.Readline
    arrGrMemList = Split(strNextLine , ",")
 Wscript.Echo "Group Name: ||"&arrGrMemList(0)&"||"
 Wscript.Echo "Member Name: ||"&arrGrMemList(1)&"||"  
Set objGroup = GetObject ("LDAP://cn=" & arrGrMemList(0) & ",ou=Web,ou=CS,dc=abc,dc=com")
objGroup.PutEx ADS_PROPERTY_APPEND,"member", Array("cn="& arrGrMemList(1) & ",cn=users,dc=abc,dc=com")
objGroup.SetInfo
Loop
***********************************************************************************

Here arrGrMemList(0) is the user group name and arrGrMemList(1) is the member or user that needs to be added. At this point we have only one member that needs to be added per group.
There is no problem with this script if all the users exist in USERS container. They are spread in some other OU's in the same domain. I dont know how to chance this script to find the user in the entire domain and add it to that group without just looking at just one container or OU.
Also if anybody can give me some links to start with LDAP and AD script writing and understanding how to write these scripts that would be great.

Thanks.
0
Comment
Question by:r5ur5
1 Comment
 
LVL 6

Accepted Solution

by:
tone28 earned 500 total points
ID: 16582562

' Prepare Connection
Set oCon = CreateObject("ADODB.Connection")
oCon.Provider = "ADsDSOObject"
oCon.Open "Active Directory Provider"

Base = "<LDAP://dc=abc,dc=com>;"
Attr = "distinguishedName;"
Tree = "SubTree"

' Your Code
Const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile ("c:\temp\studentmembers.csv", ForReading)
 On Error Resume Next
Const ADS_PROPERTY_APPEND = 3
Do Until objTextFile.AtEndOfStream
    strNextLine = objTextFile.Readline
    arrGrMemList = Split(strNextLine , ",")
 Wscript.Echo "Group Name: ||"&arrGrMemList(0)&"||"
 Wscript.Echo "Member Name: ||"&arrGrMemList(1)&"||"  
Set objGroup = GetObject ("LDAP://cn=" & arrGrMemList(0) & ",ou=Web,ou=CS,dc=abc,dc=com")
objGroup.PutEx ADS_PROPERTY_APPEND,"member", Array(GetUsersDN(arrGrMemList(1)))
objGroup.SetInfo
Loop


Function GetUsersDN(UserName)
      
      sfilter = "(&(objectClass=user)(objectCategory=person)(displayName=" & UserName & "));"
      Set oRS = oCon.Execute(Base & sfilter & Attr & Tree)
      
      oRS.MoveFirst
      While Not oRS.EOF
          GetUsersDN = oRS.Fields(0).Value
          oRS.MoveNext
      Wend
End Function
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

AutoHotkey is an excellent, free, open source programming/scripting language for Windows. It started out as a keyboard/mouse macros product, but has expanded into a robust language. This article provides an introduction to it, with links to addition…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses
Course of the Month14 days, 4 hours left to enroll

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question