[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

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

Posted on 2011-02-11
6
Medium Priority
?
532 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 2000 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
Are your AD admin tools letting you down?

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.

 

Author Comment

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

Accepted Solution

by:
IceCode earned 2000 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

Are your AD admin tools letting you down?

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

Uncontrolled local administrators groups within any organization pose a huge security risk. Because these groups are locally managed it becomes difficult to audit and maintain them.
How to deal with a specific error when using the Enable-RemoteMailbox cmdlet to create a mailbox in the cloud-based service, for an existing user in an on-premises Active Directory.
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 to another domain controller. Log onto the new domain controller with a user account t…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Suggested Courses

649 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