Solved

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

Posted on 2011-02-11
6
527 Views
Last Modified: 2012-06-27
I have run the script from solution:
http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_24978862.html

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
 
objRS.MoveFirst
Do Until objRS.EOF
	Set objGroup = GetObject("LDAP://" & Replace(objRS.Fields("distinguishedName").Value,"/","\/"))
	WScript.Echo objGroup.cn & "," & memberString(objGroup)
 
	
	objRS.MoveNext
Loop
 
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 & objmember.cn & "; "
		Next
	End If
	If Right(out,2) = "; " Then out = Left(out,Len(out)-2)
	memberString = out
End Function

Open in new window

0
Comment
Question by:AzleISD
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 4

Assisted Solution

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

Author Comment

by:AzleISD
ID: 34872995
awesome now I just need to get it to run just in the ou not the entire AD...
0
 
LVL 4

Expert Comment

by:IceCode
ID: 34873002
oh sorry, give me a few minutes.
0
Free NetCrunch network monitor licenses!

Only on Experts-Exchange: Sign-up for a free-trial and we'll send you your permanent license!

Here is what you get: 30 Nodes | Unlimited Sensors | No Time Restrictions | Absolutely FREE!

Act now. This offer ends July 14, 2017.

 

Author Comment

by:AzleISD
ID: 34873014
not a problem Thanks for the quick response!!
0
 
LVL 4

Accepted Solution

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

Author Closing Comment

by:AzleISD
ID: 34873640
That is is thanks for your help!
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

In-place Upgrading Dirsync to Azure AD Connect
This article shows the method of using the Resultant Set of Policy Tool to locate Group Policy that applies a particular setting.
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

691 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