Tuesday, February 8, 2011

Enumerating Members of a Group

This is a VB script that queries members in a specified group in AD and list them in an Execl work sheet. 

Dim objGroup, objExcel, iRow, strUser
Set objGroup = GetObject(ldap://cn=ACCOUNTING,ou=MARKETING,DC=SUNSET,DC=SIGNS,DC=LCL/)
Set objExcel = CreateObject("Excel.Application")
With objExcel
.SheetsInNewWorkbook = 1
.Workbooks.Add
.Visible = True
.Worksheets.Item(1).Name = mid(objGroup.Name, instr(1,objGroup.Name,"=") + 1 ) 'set Worksheet name to that of the DL
rem .Worksheets.Item(1).Name = dldump
.Cells(1,1) = "UserID"
irow=2
For Each strUser in objGroup.Member
Set objUser = GetObject("LDAP://" & strUser)
.Cells(iRow,1) = objUser.samaccountname
irow=irow + 1
Next
.Columns(1).entirecolumn.autofit
End With
Set objExcel = Nothing
Set objGroup = Nothing

No comments:

Post a Comment