Categories /
Scripting /
VBScript for Windows
This script binds to a specific security group in an Active Directory domain and returns a list of all members in this group.
Option Explicit
Dim objRootDSE, strDomain, objGroup, objUser, strGroupMembers
' Retrieve domain information
Set objRootDSE = GetObject("LDAP://RootDSE")
strDomain = objRootDSE.Get("DefaultNamingContext")
' Bind to the group
Set objGroup = GetObject("LDAP://CN=TestGroup,ou=AdGroups,ou=Ad Client Users," & strDomain)
' Iterate through the user objects in the group
For Each objUser In objGroup.Members
' Append users Name to the output string
strGroupMembers = strGroupMembers & objUser.Name & VbCrLf
Next
' Print out the user list
MsgBox strGroupMembers
The script binds to a group called 'TestGroup' wich is located in the OU AdGroups, wich again is located in another OU called 'Ad Client Users' in the domain.
Set objGroup = GetObject("LDAP://CN=TestGroup,ou=AdGroups,ou=Ad Client Users," & strDomain)
The domain information (domain name for the Active Directory) is retrieved dynamically by calling the root of the directory using the LDAP protocol and is stored in the string called strDomain.
Set objRootDSE = GetObject("LDAP://RootDSE")
strDomain = objRootDSE.Get("DefaultNamingContext")
This means that you will have to change the path for the group you will like to search in your own Active Directory but you can leave the domain name as is.
07-10-2009 by Thomas Møller Nexø
Unique visits since publich date
9329
Comment on this article