re: Active Directory Groups

Author Message
reydelcompas

  • Total Posts : 11
  • Scores: 0
  • Reward points : 0
  • Joined: 7/13/2011
  • Status: offline
re: Active Directory Groups Wednesday, January 25, 2012 1:26 PM (permalink)
0
I have this code which I found online. It serves my purposes. I want to populate membership to different groups
Code:
Option Explicit
Dim strOU, strOU1, strGroup, strTextGroup, strUser, strFile
Dim strDNSDomain, objRootDSE, objFSO, objTextFile, intCounter
Dim objOU, objUser, objGroup

Const ForReading = 1
Const ADS_PROPERTY_APPEND = 3
intCounter = 0

'  strUser ("CN=Pete ,") must exist in your OU.
'  Set the Name of the OU which holds the user and groups
'  NB introduce another variable if user and group are in different OUs
strUser = "CN=Joyce ,"
strOU = "OU=BCI_Users ,"
strOU1 = "OU=Bonnie,OU=SOMEDB,OU=BCI_Users ,"
strFile = "c:\Users\myName\ADGroupsList.txt"

'  Open the file For Reading your Group Names
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile(strFile, ForReading)

'  Here is the loop
Do
strTextGroup = objTextFile.ReadLine
strGroup = "CN=" & strTextGroup & " ,"

'  Bind to Active Directory and get LDAP name
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("DefaultNamingContext")

'  Prepare the OU and the Group
Set objOU =GetObject("LDAP://" & strOU & strDNSDomain)
Set objGroup = GetObject("LDAP://"& strGroup & strOU & strDNSDomain)

'  On Error Resume next
'  Add user to Group with .PutEx (put extended)
Set objGroup = GetObject ("LDAP://"& strGroup & strOU & strDNSDomain)
objGroup.PutEx ADS_PROPERTY_APPEND, _
"member", Array(strUser & strOU & strDNSDomain)
objGroup.SetInfo
intCounter = intCounter +1
WScript.Echo strUser & " has " & intCounter & " new groups"

Loop Until objTextFile.AtEndOfLine = true
objTextFile.Close
WScript.Quit
 
Questions:
1. I get error pointing to Line #33 (Loop until objTextFile.AtEndOfLine = true)
2. Do I need a strOU for both the user and group. Can you provide the syntax? Right now I am using:
strUser = "CN=Joyce ," //is this correct?
strOU = "OU=BCI_Users ," //this is my path to the GROUP. Joyce is in BCI_Users..
strOU1 = "OU=Bonnie,OU=SOMEDB,OU=BCI_Users ,"  //this is the path to the user
3. How can I construct an array to have several users to be added to one group.
 
Thank you very much for the help

 
#1
    59cobalt

    • Total Posts : 981
    • Scores: 91
    • Reward points : 0
    • Joined: 7/17/2011
    • Status: offline
    re: Active Directory Groups Monday, January 30, 2012 12:08 AM (permalink)
    0
    reydelcompas
    Questions:
    1. I get error pointing to Line #33 (Loop until objTextFile.AtEndOfLine = true)
    If you want someone to troubleshoot an error, providing the exact error code an message is not optional. That said, I'd start with using
    Loop Until objTextFile.AtEndOfStream
    instead of
    Loop Until objTextFile.AtEndOfLine = true]
    because that's what you actually want to match.
    reydelcompas
    2. Do I need a strOU for both the user and group. Can you provide the syntax? Right now I am using:
    strUser = "CN=Joyce ," //is this correct?
    strOU = "OU=BCI_Users ," //this is my path to the GROUP. Joyce is in BCI_Users..
    strOU1 = "OU=Bonnie,OU=SOMEDB,OU=BCI_Users ,"  //this is the path to the user
    The syntax looks correct to me. However, you're never using strOU1, so it seems you attempt to add a non-existing DN to the group.
    reydelcompas
    3. How can I construct an array to have several users to be added to one group.
    When in doubt, read the documentation.
     
    #2

      Online Bookmarks Sharing: Share/Bookmark

      Jump to:

      Current active users

      There are 0 members and 1 guests.

      Icon Legend and Permission

      • New Messages
      • No New Messages
      • Hot Topic w/ New Messages
      • Hot Topic w/o New Messages
      • Locked w/ New Messages
      • Locked w/o New Messages
      • Read Message
      • Post New Thread
      • Reply to message
      • Post New Poll
      • Submit Vote
      • Post reward post
      • Delete my own posts
      • Delete my own threads
      • Rate post

      2000-2012 ASPPlayground.NET Forum Version 3.9