Login | |
|
 |
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
|
|
| |
|
|
|
 |
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
|
|
| |
|
|
|
|
|