BNettles73
asked on
Active Directory - Distribution List Script
Sirbounty was nice enough to write a script for me ... it pulls Active Directory DL members to a spreadsheet ... I'd like to take it one more level and also pull the SMTP addresses of the Distribution List members.
Accepted Answer from sirbounty feedback
Date: 02/19/2005 02:00PM CST
Grade: A
Accepted Answer
This should give you what you're looking for...
Dim objGroup, objExcel, iRow, strUser
Set objGroup = GetObject("LDAP://CN=myDis tList,ou=M essaging,d c=myDomain ,dc=com")
Set objExcel = CreateObject("Excel.Applic ation")
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
irow=1
For Each strUser in objGroup.Member
Set objUser = GetObject("LDAP://" & strUser)
.Cells(iRow,1) = objUser.CN
irow=irow + 1
Next
.Columns(1).entirecolumn.a utofit
End With
Set objExcel = Nothing
Set objGroup = Nothing
Accepted Answer from sirbounty feedback
Date: 02/19/2005 02:00PM CST
Grade: A
Accepted Answer
This should give you what you're looking for...
Dim objGroup, objExcel, iRow, strUser
Set objGroup = GetObject("LDAP://CN=myDis
Set objExcel = CreateObject("Excel.Applic
With objExcel
.SheetsInNewWorkbook = 1
.Workbooks.Add
.Visible = True
.Worksheets.Item(1).Name = mid(objGroup.Name, instr(1,objGroup.Name,"=")
irow=1
For Each strUser in objGroup.Member
Set objUser = GetObject("LDAP://" & strUser)
.Cells(iRow,1) = objUser.CN
irow=irow + 1
Next
.Columns(1).entirecolumn.a
End With
Set objExcel = Nothing
Set objGroup = Nothing
ASKER
So it would look like this?
Dim objGroup, objExcel, iRow, strUser
Set objGroup = GetObject("LDAP://CN=myDis tList,ou=M essaging,d c=myDomain ,dc=com")
Set objExcel = CreateObject("Excel.Applic ation")
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
irow=1
For Each strUser in objGroup.Member
Set objUser = GetObject("LDAP://" & strUser)
.Cells(iRow,1) = objUser.CN
for each email in objUser.proxyAddresses
if lcase(left(email,4)) = "smtp" then .Cells(iRow,2) = mid(email,6)
next
.Columns(1).entirecolumn.a utofit
End With
Set objExcel = Nothing
Set objGroup = Nothing
Dim objGroup, objExcel, iRow, strUser
Set objGroup = GetObject("LDAP://CN=myDis
Set objExcel = CreateObject("Excel.Applic
With objExcel
.SheetsInNewWorkbook = 1
.Workbooks.Add
.Visible = True
.Worksheets.Item(1).Name = mid(objGroup.Name, instr(1,objGroup.Name,"=")
irow=1
For Each strUser in objGroup.Member
Set objUser = GetObject("LDAP://" & strUser)
.Cells(iRow,1) = objUser.CN
for each email in objUser.proxyAddresses
if lcase(left(email,4)) = "smtp" then .Cells(iRow,2) = mid(email,6)
next
.Columns(1).entirecolumn.a
End With
Set objExcel = Nothing
Set objGroup = Nothing
ASKER
I'm getting an error at line 20 -
line 20 = End With
Did I not modify the script right?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
works like a charm ... Thanks!
ASKER
One thing I noticed - it doesn't save the list ... it populates great, but what I want to do is setup monthly reporting and email the excel file. I have the script that emails the file but I'll need the script to save and close the excel doc ... is this easy to do?
Sorry to keep bothering you!
Brian
Sorry to keep bothering you!
Brian
Oh, I saw you wanted it in Excel, so I went that route. You can simply save the file - not sure off-hand how to automate that...
OR... you can change your output type to a text file and have it save with an XLS extension - which is how I usually do this....
So, you would have data in the format of
SmithT,TomSmith@myCompany. com
so that it would be CSV and convert easily when opened.
I can dig deeper for the auto-save of Excel, if that's what you'd prefer...
OR... you can change your output type to a text file and have it save with an XLS extension - which is how I usually do this....
So, you would have data in the format of
SmithT,TomSmith@myCompany.
so that it would be CSV and convert easily when opened.
I can dig deeper for the auto-save of Excel, if that's what you'd prefer...
ASKER
I made a couple of changes ... can't figure out how to add the spreadsheet headers ... I can handle the save manually ... the last change I want to make is to add "Display Name" and "Email Address" as the headers of the two columns. I bumped the irow down to 2 and changed CN to displayName ... can you tell me how to add the headers?
Dim objGroup, objExcel, iRow, strUser, strDL
strDL = inputBox("What is the name of the Distribution List?","Distribution List")
Set objGroup = GetObject("LDAP://CN=" & strDL & ",ou=Distribution Lists,ou=Accounts,dc=Corp,
Set objExcel = CreateObject("Excel.Applic
With objExcel
.SheetsInNewWorkbook = 1
.Workbooks.Add
.Visible = True
.Worksheets.Item(1).Name = mid(objGroup.Name, instr(1,objGroup.Name,"=")
irow=2
For Each strUser in objGroup.Member
Set objUser = GetObject("LDAP://" & strUser)
.Cells(iRow,1) = objUser.displayName
for each email in objUser.proxyAddresses
if lcase(left(email,4)) = "smtp" then .Cells(iRow,2) = mid(email,6)
next
irow=irow + 1
Next
.Columns(2).entirecolumn.a
End With
Set objExcel = Nothing
Set objGroup = Nothing
just before your
irow=2 line...
Enter:
irow=2 'existing line
.Cells(1,1) = "Display Name" 'new line
.Cells(1,2) = "Email Address" 'new line
For Each strUser in objGroup.Member 'existing line
irow=2 line...
Enter:
irow=2 'existing line
.Cells(1,1) = "Display Name" 'new line
.Cells(1,2) = "Email Address" 'new line
For Each strUser in objGroup.Member 'existing line
ASKER
sweet ... I seriously appreciate you helping me with this task ...
Thanks again -
Thanks again -
Glad to have helped. :)
hi,
I copied the code into notepad, edited the ldap string, saved as .vbs but I do not see a file.
the black screen flashed then disappears. where does the output go or what am i doing wrong?
Thanks.
I copied the code into notepad, edited the ldap string, saved as .vbs but I do not see a file.
the black screen flashed then disappears. where does the output go or what am i doing wrong?
Thanks.
For Each strUser in objGroup.Member
Set objUser = GetObject("LDAP://" & strUser)
.Cells(iRow,1) = objUser.CN
for each email in objUser.proxyAddresses
if lcase(left(email,4)) = "smtp" then .Cells(iRow,2) = mid(email,6)
next