Petri IT Knowledgebase Forums
 

Petri.co.il forums Home Forums Start Page Forums Frequently Asked Questions FAQ Member List Members List
Go Back   Petri IT Knowledgebase Forums > Microsoft Networking Services > Active Directory
Petri.co.il is happy to award auglan the title of Most Valuable Member !!!
Register Calendar Calendar Search Petri IT Knowledgebase Forums Search Todays Posts Today's Posts Mark Forums Read

Notices

Get a list of users in a Distribution list or Security Group

Get a list of users in a Distribution list or Security Group

this thread has 10 replies and has been viewed 31950 times

Closed Thread
 
Thread Tools Search this Thread Display Modes
  #1  
Old 7th June 2006, 10:11
JDMils JDMils is offline
Member
Someone to look up to
 
 Join Date: Dec 2005
  6 month star 12 month star
 Location: Melbourne, Australia
 Posts: 821
 Reputation: JDMils is on a distinguished road (21)
Default Get a list of users in a Distribution list or Security Group

Can I use DSQuery to do this and if so, what's the syntax?

Windows2003
__________________
|
+-- JDMils
|
+-- System Admin, DotNet programmer & Jack of all trades
|
  #2  
Old 7th June 2006, 13:00
wullieb1 wullieb1 is offline
Moderator
 
 Join Date: Jul 2005
  6 month star 12 month star
 Location: Bris Vegas, Australia
 Posts: 6,438
 Reputation: wullieb1 is a splendid one to beholdwullieb1 is a splendid one to beholdwullieb1 is a splendid one to beholdwullieb1 is a splendid one to beholdwullieb1 is a splendid one to beholdwullieb1 is a splendid one to behold (690)
Default Re: Get a list of users in a Distribution list or Security Group

Quote:
Originally Posted by JDMils
Can I use DSQuery to do this and if so, what's the syntax?

Windows2003
Personally i would use CSVDE.

This is the syntax i use to extract user info from AD

csvde -d "ou=users,ou=whatever,ou=whatever,dc=whatever,dc=c om" -l "cn,department,title,mail,telephonenumber,mobi le" -f filepath

This then extract the info

CN
Department
Title
Mail
Telephone Number
Mobile Number
  #3  
Old 8th June 2006, 03:15
guyt's Avatar
guyt guyt is offline
[MSFT]
Guru
 
 Join Date: Nov 2003
  6 month star 12 month star
 Location: Israel
 Posts: 1,766
  Send a message via MSN to guyt
 Reputation: guyt is a name known to allguyt is a name known to allguyt is a name known to allguyt is a name known to allguyt is a name known to allguyt is a name known to all (592)
Default Re: Get a list of users in a Distribution list or Security Group

If you also require an expansion of nested groups, you might want to look at the following script I once wrote:
http://guy.netguru.co.il/uploads/EnumDLGroup.vbs.txt

Code:
' EnumDLGroup.vbs
' The script will enumerate all members (users and contacts) of a 
' given Distribution List.
' Nested groups are expanded.
' No duplicates will be output as the script uses Scripting.Dictionary object
' for intermidiate membership storage.

' Created by Guy Teverovsky August 03, 2005

Option Explicit


Dim rs,conn
Set conn = CreateObject("ADODB.Connection")
conn.Provider = "ADSDSOObject"
conn.Open "ADs Provider"


Dim oMembersList
Set oMembersList = CreateObject("Scripting.Dictionary")
oMembersList.CompareMode = vbTextCompare

Dim arrKeys,i,sDLsamAccountName,sGroupDN

'----------Start Change me------------------
sDLsamAccountName = "TEST"
'-----------End Change me-------------------


sGroupDN = findDLGroup(sDLsamAccountName)
enumGroupMembers sGroupDN


arrKeys = oMembersList.Keys   ' Get the keys.
For i = 0 To oMembersList.Count -1 
	WScript.Echo arrKeys(i) & ": " & oMembersList(arrKeys(i))
Next


'Clean up
Set conn 		= Nothing
Set oMembersList	= Nothing


'==============================================================
'			Subroutines
'==============================================================


'==============================================================
' Locate a distribution list by sAMAccountName
' 
' Parameters:
'	- sAMAccountName: the NT-style name of the DL
'==============================================================

Function findDLGroup(sAMAccountName)
	Dim objRootDSE, domainContainer, oGroup,ldapStrExchDL
	Set objRootDSE	= GetObject("LDAP://RootDSE")
	domainContainer = objRootDSE.Get("defaultNamingContext")
	ldapStrExchDL = "<LDAP://" & domainContainer & _
		">;(&(objectCategory=group)(!groupType:1.2.840.113556.1.4.803:=2147483648)(sAMAccountName=" & sAMAccountName & "));adspath;subtree"
	Set rs = conn.Execute(ldapStrExchDL)
	If Not rs.EOF Then
		Set oGroup = GetObject (rs.Fields(0).Value)
		findDLGroup = oGroup.distinguishedName
	Else
		WScript.Echo "Group not found"
		WScript.Quit 0
	End If
	Set objRootDSE = Nothing
End Function


'==============================================================
' Recursive subroutine to enumerate members of a given group
' 
' Parameters:
'	- sObjDN: group object's DN to enumerate it's members
'==============================================================
Sub enumGroupMembers(sObjDN)
	Dim oContainer, obj, sDN	

  	Set oContainer=GetObject ("LDAP://" & sObjDN)  	
	
	For each obj in oContainer.members
  		Select Case LCase(obj.Class)  	
		Case "user" , "contact"
			If Not oMembersList.Exists(obj.sAMAccountName) Then
				oMembersList.Add obj.sAMAccountName, obj.Get("mail")
			End If
		Case "contact"
			If Not oMembersList.Exists(obj.Get("mail")) Then
				oMembersList.Add obj.Get("mail"), obj.Get("mail")
			End If								
		Case "group"
			EnumGroupMembers obj.distinguishedName
		End Select 		
	Next
End Sub
__________________
Guy Teverovsky
http://blogs.technet.com/b/isrpfeplat/
"Smith & Wesson - the original point and click interface"
  #4  
Old 12th April 2007, 23:27
Amdocs Amdocs is offline
Casual
Casual
 
 Join Date: Apr 2007
  6 month star 12 month star
 Posts: 3
 Reputation: Amdocs is on a distinguished road (10)
Unhappy Re: Get a list of users in a Distribution list or Security Group

Hi Mr. Guy T,

First of all thanks to your reference over here.

I'm trying to use it, however from some unknown reasons it gave me nothing...
In function 'findDLGroup' you check if 'Not rs.EOF' and from unknown reason it's goes to the else part... i tried to play with it and change it, with no success

I truly hope you could help me to determine what could be the problem over there?

Thanks a lot!
Eldad
  #5  
Old 13th April 2007, 00:48
guyt's Avatar
guyt guyt is offline
[MSFT]
Guru
 
 Join Date: Nov 2003
  6 month star 12 month star
 Location: Israel
 Posts: 1,766
  Send a message via MSN to guyt
 Reputation: guyt is a name known to allguyt is a name known to allguyt is a name known to allguyt is a name known to allguyt is a name known to allguyt is a name known to all (592)
Default Re: Get a list of users in a Distribution list or Security Group

Have you changed the saMAccountName of the DL group you are trying to enumerate ? Or do you need to enumerate a bunch of DL grouos ?
__________________
Guy Teverovsky
http://blogs.technet.com/b/isrpfeplat/
"Smith & Wesson - the original point and click interface"
  #6  
Old 15th April 2007, 11:18
Amdocs Amdocs is offline
Casual
Casual
 
 Join Date: Apr 2007
  6 month star 12 month star
 Posts: 3
 Reputation: Amdocs is on a distinguished road (10)
Thumbs up Re: Get a list of users in a Distribution list or Security Group

Hi,

Thanks a lot to your quick responce.

yes, i've chenge it, the code looks like that after changes were made in the functions you made:

ldapStrExchDL : <LDAP://DC=corp,DC=amdocs,DC=com>;(&(objectCategory=group) (!groupType:1.2.840.113556.1.4.803:=214748364(sA MAccountName=*IMIS Clarify CRM Projects));adspath;subtree

the only thing that i changed is the 'sAMAccountName=' part, all other data is retrieved by your functions.

After running this query i get a nul record set.

Thanks a lot!
Eldad
  #7  
Old 18th April 2007, 20:58
guyt's Avatar
guyt guyt is offline
[MSFT]
Guru
 
 Join Date: Nov 2003
  6 month star 12 month star
 Location: Israel
 Posts: 1,766
  Send a message via MSN to guyt
 Reputation: guyt is a name known to allguyt is a name known to allguyt is a name known to allguyt is a name known to allguyt is a name known to allguyt is a name known to all (592)
Default Re: Get a list of users in a Distribution list or Security Group

Looks like the group is a security group. The filter in my script looks only for distribution groups.

Just change the following line:
Code:
	ldapStrExchDL = "<LDAP://" & domainContainer & _
		">;(&(objectCategory=group)(!groupType:1.2.840.113556.1.4.803:=2147483648)(sAMAccountName=" & sAMAccountName & "));adspath;subtree"
to:
Code:
	ldapStrExchDL = "<LDAP://" & domainContainer & _
		">;(&(objectCategory=group)(objectclass=group)(sAMAccountName=" & sAMAccountName & "));adspath;subtree"
This will search for both distribution AND security groups
__________________
Guy Teverovsky
http://blogs.technet.com/b/isrpfeplat/
"Smith & Wesson - the original point and click interface"
  #8  
Old 19th April 2007, 11:26
Amdocs Amdocs is offline
Casual
Casual
 
 Join Date: Apr 2007
  6 month star 12 month star
 Posts: 3
 Reputation: Amdocs is on a distinguished road (10)
Talking Re: Get a list of users in a Distribution list or Security Group

Hi,

Thanks a lot!

It's solve the problem.

Have a nice day!

Eldad
  #9  
Old 20th April 2007, 02:06
JDMils JDMils is offline
Member
Someone to look up to
 
 Join Date: Dec 2005
  6 month star 12 month star
 Location: Melbourne, Australia
 Posts: 821
 Reputation: JDMils is on a distinguished road (21)
Default Re: Get a list of users in a Distribution list or Security Group

Just out of curiosity, how does one debug a VBS script? Can you trace the code line-by-line and have watches on variables like .Net?
__________________
|
+-- JDMils
|
+-- System Admin, DotNet programmer & Jack of all trades
|
  #10  
Old 20th April 2007, 13:14
biggles77's Avatar
biggles77 biggles77 is offline
Administrator
 
 Join Date: Dec 2003
  6 month star 12 month star
 Location: Nowhere that I like.
 Posts: 10,768
 Reputation: biggles77 is a splendid one to beholdbiggles77 is a splendid one to beholdbiggles77 is a splendid one to beholdbiggles77 is a splendid one to beholdbiggles77 is a splendid one to beholdbiggles77 is a splendid one to beholdbiggles77 is a splendid one to behold (738)
Default Re: Get a list of users in a Distribution list or Security Group

Quote:
Originally Posted by JDMils View Post
Just out of curiosity, how does one debug a VBS script? Can you trace the code line-by-line and have watches on variables like .Net?
how to debug a vb script
__________________
"There I stood at the bar, wearing a Mae West, no jacket, and beginning to leak blood from my torn boot. None of the golfers took any notice of me - after all, I wasn't a member!" Kenneth Lee - after being shot down during the Battle of Britain on the 18th August 1940.

************************************************** **********************
** Remember to give credit where credit is due and leave reputation points where appropriate **
************************************************** **********************
Closed Thread


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Export Active Directory data Stefan Active Directory 35 24th July 2008 00:09
Help. Can't C Clients in WSUS? habibalby Active Directory 22 16th August 2006 18:50
domain users and group help!! badgerbrian Active Directory 2 24th July 2006 08:28
OWA Distribution List twrizzo Exchange 2000 / 2003 0 21st September 2005 17:39
group strategy SpyD Active Directory 13 23rd May 2005 23:16


All times are GMT +3. The time now is 10:03.

Steel Blue 3.5.4 vBulletin Style ©2006 vBEnhanced
Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
 

Valid XHTML 1.0!   Valid CSS!

Copyright 2005 Daniel Petri