Solved

Querying Active Directory group membership information

Posted on 2013-11-30
6
961 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 250 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 150 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

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 …
Disabling the Directory Sync Service Account in Office 365 will stop directory synchronization from working.
This tutorial will give a short introduction and overview of Backup Exec 2012 and how to navigate and perform basic functions. Click on the Backup Exec button in the upper left corner. From here, are global settings for the application such as conne…
This tutorial will walk an individual through locating and launching the BEUtility application to properly change the service account username and\or password in situation where it may be necessary or where the password has been inadvertently change…

910 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

21 Experts available now in Live!

Get 1:1 Help Now