Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Another n00b asking for help

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,46296
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Another n00b asking for help
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Another n00b asking for help - 4/24/2007 7:17:56 PM   
  Zebed00

 

Posts: 2
Score: 0
Joined: 4/24/2007
Status: offline
Hi,

I'm a systems guy who's been asked to deal with Nested Distribution Lists in Active Directory/Exchange 03.  I've been trying to get this code I found on the net working for the last couple of days and can't really get my head around it.  Any help you can offer would be hugely appreciated as I haven't touched any code for around 15 years :(

The lines I've emboldened are the lines where either VBS Edit or within MS applications the script fails.

Am I missing something really basic here please guys?

Thanks in advance,





' EnumDLGroup.vbs
' The script will enumerate all members (users and contacts) of a
' given Distribution List.
' Nested groups are expanded.
' No duplicates will be output as the script uses Scripting.Dictionary object
' for intermidiate membership storage.

' Created by Guy Teverovsky August 03, 2005

Option Explicit

Dim rs, conn
Dim oMembersList
Public Sub Main()


Set conn = CreateObject("ADODB.Connection")
conn.Provider = "ADSDSOObject"
conn.Open "ADs Provider"



Set oMembersList = CreateObject("Scripting.Dictionary")
oMembersList.CompareMode = vbTextCompare

Dim arrKeys, i, sDLsamAccountName, sGroupDN

'----------Start Change me------------------
sDLsamAccountName = "GL-Principals"
'-----------End Change me-------------------


sGroupDN = findDLGroup(sDLsamAccountName)
enumGroupMembers sGroupDN


arrKeys = oMembersList.Keys   ' Get the keys.
For i = 0 To oMembersList.Count - 1
       'debug.print arrKeys(i) & ": " & oMembersList(arrKeys(i))
       Debug.Print arrKeys(i) & ": " & oMembersList(arrKeys(i))
Next


'Clean up
On Error Resume Next
   rs.Close
   Set rs = Nothing
   conn.Close
   Set conn = Nothing
   Set oMembersList = Nothing

End Sub

'==============================================================
'                      Subroutines
'==============================================================


'==============================================================
' Locate a distribution list by sAMAccountName
'
' Parameters:
'       - sAMAccountName: the NT-style name of the DL
'==============================================================

Function findDLGroup(sAMAccountName)
       Dim objRootDSE, domainContainer, oGroup, ldapStrExchDL
       Set objRootDSE = GetObject("LDAP://RootDSE")
       domainContainer = objRootDSE.Get("defaultNamingContext")
       ldapStrExchDL = "<LDAP://" & domainContainer & _
               ">;(&(objectCategory=group)(!groupType:1.2.840.113556.1.4..803:2147483648)(sAMAccountName=" & sAMAccountName & "));adspath;subtree"
       Set rs = conn.Execute(ldapStrExchDL)
       If Not rs.EOF Then
              Set oGroup = GetObject(rs.Fields(0).Value)
              findDLGroup = oGroup.distinguishedName
       Else
              Debug.Print "Group not found"
              'WScript.Quit 0
       End If
       Set objRootDSE = Nothing
End Function


'==============================================================
' Recursive subroutine to enumerate members of a given group
'
' Parameters:
'       - sObjDN: group object's DN to enumerate it's members
'==============================================================
Sub enumGroupMembers(sObjDN)
       Dim oContainer, obj, sDN

        Set oContainer = GetObject("LDAP://" & sObjDN)
      
       For Each obj In oContainer.Members
              Select Case LCase(obj.Class)
              Case "user", "contact"
                      If Not oMembersList.Exists(obj.sAMAccountName) Then
                              oMembersList.Add obj.sAMAccountName, obj.Get("mail")
                      End If
              Case "contact"
                      If Not oMembersList.Exists(obj.Get("mail")) Then
                              oMembersList.Add obj.Get("mail"), obj.Get("mail")
                      End If
              Case "group"
                      enumGroupMembers obj.distinguishedName
              End Select
       Next
End Sub
 
 
Post #: 1
 
 RE: Another n00b asking for help - 4/25/2007 6:51:26 AM   
  dm_4ever


Posts: 2430
Score: 38
Joined: 6/29/2006
From: Orange County, California
Status: offline
you might try deleting the colored section:

ldapStrExchDL = "<LDAP://" & domainContainer & ">;(&(objectCategory=group)(!groupType:1.2.840.113556.1.4..803:2147483648)(sAMAccountName=" & sAMAccountName & "));adspath;subtree"

You can always open the AD mmc and create your query under "Saved Queries" to return what you want, then export the query, copy and paste it into your code, and modify as needed.

_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to Zebed00)
 
 
Post #: 2
 
 RE: Another n00b asking for help - 4/25/2007 9:48:19 AM   
  Zebed00

 

Posts: 2
Score: 0
Joined: 4/24/2007
Status: offline
Thanks very much, will go for the AD MMC tomorrow - hadn't thought of that



Got my interest up in code again now, so I'm gonna have to get learning

(in reply to dm_4ever)
 
 
Post #: 3
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Another n00b asking for help Page: [1]
Jump to:





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
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts