Vbscript to enum groups and group memebrs from a specific OU not from Root of  AD

Posted on 2011-02-11
Last Modified: 2012-06-27
I have run the script from solution:

It works great for just Distribution groups. The problem I have is that some of the groups we use for distributiol groups are Security groups. I have organized them in a ou in ad the Dn is:
OU=Groups - Distribution,DC=azle,DC=esc11,DC=net

I need to run this script to look at both dist groups and security groups.. Please Help!! thanks..
Set oRootDSE = GetObject("LDAP://RootDSE")
Set objConn = CreateObject("ADODB.Connection")
Set objComm =   CreateObject("ADODB.Command")
objConn.Provider = "ADsDSOObject"
objConn.Open "Active Directory Provider"
Set objComm.ActiveConnection = objConn
objComm.Properties("Page Size") = 1000
strBase   =  "<LDAP://" & oRootDSE.get("defaultNamingContext") & ">;"
strFilter = "(sAMAccountType=268435457);" 
strAttrs  = "distinguishedName,memberof,sAMAccountName;"
strScope  = "subtree"
objComm.CommandText = strBase & strFilter & strAttrs & strScope
Set objRS = objComm.Execute
Do Until objRS.EOF
	Set objGroup = GetObject("LDAP://" & Replace(objRS.Fields("distinguishedName").Value,"/","\/"))
	WScript.Echo & "," & memberString(objGroup)
Set oRootDSE = Nothing
Set objConn = Nothing
Set objComm = Nothing
Set objUser = Nothing
Function memberString(objGroup)
	If Not IsEmpty(objgroup.member) Then
		For Each memberDN In objGroup.GetEx("member")
			Set objMember = GetObject("LDAP://" & memberDN)
			out = out & & "; "
	End If
	If Right(out,2) = "; " Then out = Left(out,Len(out)-2)
	memberString = out
End Function

Open in new window

Question by:AzleISD
  • 3
  • 3

Assisted Solution

IceCode earned 500 total points
ID: 34872930
Change line 10 to: strFilter = "(&(objectCategory=group));"

Author Comment

ID: 34872995
awesome now I just need to get it to run just in the ou not the entire AD...

Expert Comment

ID: 34873002
oh sorry, give me a few minutes.
Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.


Author Comment

ID: 34873014
not a problem Thanks for the quick response!!

Accepted Solution

IceCode earned 500 total points
ID: 34873051
I think it's just line 9 should be: strBase   =  "<LDAP://OU=Groups - distribution," & oRootDSE.get("defaultNamingContext") & ">;"

Author Closing Comment

ID: 34873640
That is is thanks for your help!

Featured Post

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …

863 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now