Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Export Membership for all Groups in an OU

Status
Not open for further replies.

jjdurrant

MIS
Nov 25, 2003
6
US
Hey all - I have a few hundred distro lists within a OU. I need to export the group membership for all into Excel or some other readable format.. I have found several scripts that work for one exporting group members on a single group.. but not for all groups within a OU.. Not sure it matters, but I suspect several of these groups have no members, and some have other groups nested within them.

Thanks!
 
If all or your groups are in one OU, you could modify the following script for what you need:

on error resume next

'************************************************
'Setup excel for output
set xapp = WScript.CreateObject("Excel.Application")
xapp.Visible = True

' Make a new Excel workbook:
set workbook = xapp.Workbooks.Add
set worksheet = workbook.Worksheets("sheet1")
'***********************************************

dim output, objOU, objContainer,subou,testarray,count,workstation,temp,temparray,y
Set objOU = GetObject("LDAP://ou=Security,ou=Groups,ou=XXX,dc=xxx,dc=com")
y=1
worksheet.cells(y,1).value="Group Name"
worksheet.cells(y,2).value="Description"
worksheet.cells(y,3).value="# of Users in Group"
worksheet.cells(y,4).value="Count"
worksheet.Columns(1).ColumnWidth=35
worksheet.Columns(2).ColumnWidth=55
worksheet.Columns(3).ColumnWidth=20
worksheet.Columns(4).ColumnWidth=5
worksheet.Cells(y, 1).Font.Italic = True
worksheet.Cells(y, 1).Font.Bold = True
worksheet.Cells(y, 2).Font.Italic = True
worksheet.Cells(y, 2).Font.Bold = True
worksheet.Cells(y, 3).Font.Italic = True
worksheet.Cells(y, 3).Font.Bold = True
worksheet.Cells(y, 4).Font.Italic = True
worksheet.Cells(y, 4).Font.Bold = True
numero=0
For Each objContainer in objOU

subou=objcontainer.name

temp=objcontainer.info
temparray=split(temp,vbcr)
temp=temparray(0)
numero=numero+1


Set objOU = GetObject("LDAP://"+subou+",ou=Security,ou=Groups,ou=XXX,dc=xxx,dc=com")
count=0
for each group in objOU.Members
count=count+1
next
temparray=split(subou,"=")
subou=temparray(1)
worksheet.cells(y+1,1).value=subou
worksheet.cells(y+1,2).value=temp
worksheet.cells(y+1,3).value=count
worksheet.cells(y+1,4).value=numero
y=y+1
next
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top