Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Querying Active Directory group membership information

Posted on 2013-11-30
6
Medium Priority
?
1,025 Views
Last Modified: 2014-01-14
Good day experts,

I'm trying to query active directory with vbscript to get the membership information of a specific group.

Using an application called dsa.msc I can query this information manually but I need to follow a more automated approach using vbscript.

SO what I need my script to do now, is get all the members for a given group name.

I currently have the following sample:

Set objGroup = GetObject _
  ("LDAP:// SOMETHING MUST GO HERE")
objGroup.GetInfo
 
arrMemberOf = objGroup.GetEx("member")
 
WScript.Echo "Members:"
For Each strMember in arrMemberOf
    WScript.echo strMember
Next

I just cannot get the correct parameters specified in the "LDAP:// ..... " command to get results.  Surely, if I can access the required info with dsa.msc then I should have all the necessary connectivity, access and info to run this query - I just don't know what to put in.

Please help.

Thanks
Christoff
0
Comment
Question by:PantoffelSlippers
6 Comments
 
LVL 53

Accepted Solution

by:
Will Szymkowski earned 750 total points
ID: 39686989
Powershell is much easier. You can use 1 line of code to accomplish what you are doing... Use the following command below...

Security Group (Powershell with import-module activedirectory)
Get-ADGroupMember -Identity <groupname> | select name,samaccountname


Distribution Group (run from Exchange Management Shell)
Get-DistributionGroupMember -Identity <groupname> | Select DisplayName


Will.
0
 
LVL 14

Assisted Solution

by:Ram Balachandran
Ram Balachandran earned 450 total points
ID: 39687199
Following is a sample vbscript to find members of a AD group
For your question : You need to provide DN Name of the group

Set objGroup = GetObject ("LDAP://cn=Test_Group,ou=TestOU,dc=home,dc=com")

Say Test_Group is your group name - In dsa.msc, in view > select advanced features
and then search for the group.
Open group properties and select Object

You can see the AD path of the group like home.com/SomeOU/Groupname
Now home.com (or your domain name will become Dc=home,Dc=com.


Sample Code

' List All the 'Members' and 'Member Of' of a Group
' Test_group points to the group which you need the output

On Error Resume Next

Set objGroup = GetObject ("LDAP://cn=Test_Group,ou=TestOU,dc=home,dc=com")
objGroup.GetInfo

arrMember = objGroup.GetEx("member")

WScript.Echo "Members:"
For Each strMember in arrMember
    WScript.echo strMember
Next
'------------------------------

arrMemberOf = objGroup.GetEx("memberof")
WScript.Echo "MemberOf:"
For Each strMemberOf in arrMemberOf
    WScript.echo strMemberOf
Next
'------------------------------

Open in new window


--------------------


Using Powershell first import Active directory module

http://blogs.msdn.com/b/rkramesh/archive/2012/01/17/how-to-add-active-directory-module-in-powershell-in-windows-7.aspx

Get-ADGroupMember -Identity Test_Groupname | select name,samaccountname

Replace Test_Groupname with your group
0
 

Author Comment

by:PantoffelSlippers
ID: 39687831
Thanks - let me try this out
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 9

Expert Comment

by:VirastaR
ID: 39688271
Hi,

Check this too..

[SOLVED] Active Directory Saved Query - Group Member Listing

Hope that helps :)
0
 

Author Comment

by:PantoffelSlippers
ID: 39729626
I'll try that too.

I'm really struggling with the Powershell.

One of my challenges is that results are written back to a database - that's why I also started with VBScript - easy to update SQL Server...
0
 

Author Closing Comment

by:PantoffelSlippers
ID: 39778646
Thanks experts
0

Featured Post

Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

Question has a verified solution.

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

Resolving an irritating Remote Desktop connection that stops your saved credentials from being used.
Transferring FSMO roles is done when an admin wants to split roles between certain Domain Controllers or the Domain Controller holding the Roles has been forcefully demoted using dcpromo / forceremoval
This tutorial will walk an individual through configuring a drive on a Windows Server 2008 to perform shadow copies in order to quickly recover deleted files and folders. Click on Start and then select Computer to view the available drives on the se…
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 …

963 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