Question : VBScript to export members of Groups and export to Excel

hihi,

I'm trying to Export members of Groups into Excel, each group is a new worksheet.

The answer in this question works OK:

http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_26298266.html?sfQueryTermInfo=1+10+30+distribut+excel+export+get+group+member+script

Except I would like it to just populate each worksheet, not ask me to click OK for each user.

The maximum character length for worksheet names is 31 characters, some of the groups are longer than 31 characters and the script stops there, is there any way to just cap the worksheet name at 31 characters?

thanks

Answer : VBScript to export members of Groups and export to Excel

Hi, I have commented out the WScript.Echo lines, and changed this line
      .ActiveSheet.Name= groupName

to this
      .ActiveSheet.Name= Left(groupName, 31)

Regards,

Rob.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
Option Explicit

Dim adoCommand, adoConnection, strBase, strFilter, strAttributes
Dim objRootDSE, strDNSDomain, strQuery, adoRecordset, strName,groupType,groupName,iRow
Dim objExcel,arrMembers, strMember

' Setup ADO objects.
Set adoCommand = CreateObject("ADODB.Command")
Set adoConnection = CreateObject("ADODB.Connection")
adoConnection.Provider = "ADsDSOObject"
adoConnection.Open "Active Directory Provider"
adoCommand.ActiveConnection = adoConnection

' Search entire Active Directory domain.
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("defaultNamingContext")
strBase = "<LDAP://" & strDNSDomain & ">"

' Filter on distribution groups.
strFilter = "(objectCategory=group)"

' Comma delimited list of attribute values to retrieve.
strAttributes = "distinguishedName,member,groupType,name"

' Construct the LDAP syntax query.
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
adoCommand.CommandText = strQuery
adoCommand.Properties("Page Size") = 100
adoCommand.Properties("Timeout") = 30
adoCommand.Properties("Cache Results") = False

' Run the query.
Set adoRecordset = adoCommand.Execute

Set objExcel = CreateObject("Excel.Application")
With objExcel
.SheetsInNewWorkbook = 1
.Workbooks.Add
.Visible = True

' Enumerate the resulting recordset.
Do Until adoRecordset.EOF
' Retrieve values and display.
strName = adoRecordset.Fields("distinguishedName").Value
groupType  = adoRecordset.Fields("groupType").Value
groupName  = Replace(adoRecordset.Fields("name").Value,"CN=", "")

'get only distribution groups
if groupType=2 or groupType=4 or groupType=8 then
	irow=1
	.ActiveWorkbook.Worksheets.Add
	.ActiveSheet.Name= Left(groupName, 31)
	arrMembers = adoRecordset.Fields("member").Value

	'Wscript.Echo "Distribution Group: " & strName
	If IsNull(arrMembers) Then
		'Wscript.Echo "-- <No Members>"
	Else
		For Each strMember In arrMembers
			'Wscript.Echo "-- " & strMember
			Set objRootDSE = GetObject("LDAP://"&strMember)
			.Cells(iRow,1) = Replace(objRootDSE.Name,"CN=", "")
			irow=irow + 1
		Next
	End If
End If
' Move to the next record in the recordset.
adoRecordset.MoveNext
Loop
.Columns(1).entirecolumn.autofit
End With

' Clean up.
adoRecordset.Close
adoConnection.Close
Set objExcel = Nothing
Random Solutions  
 
programming4us programming4us