This is a script that queries an AD group and writes the members of the group to an Excel spread sheet. I actually googled most of the info but I do not remember what site I got it from.
Dim objGroup, objExcel, iRow, strUser
Set objGroup = GetObject("LDAP://cn=MRKTING,ou=NEWYORK,DC=SY,DC=Domain,DC=Domain,DC=RIVERSIDE,DC=CA,DC=US")
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
Dim objGroup, objExcel, iRow, strUser
Set objGroup = GetObject("LDAP://cn=MRKTING,ou=NEWYORK,DC=SY,DC=Domain,DC=Domain,DC=RIVERSIDE,DC=CA,DC=US")
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