dmcconnell68
asked on
VBscript to list all mail enabled active directory groups with their members
I am looking for a vbscript that will list all active directory groups that are mail enabled with the members of each group. You would think this would be easy to find, but I've been googling for a couple days and havent found exactly what I need.
Thanks
Thanks
ASKER
Hi, thanks for the script, but I'm getting the following errors:
(22, 1) Microsoft VBScript compilation error: 'loop' without 'do'
I changed line 22 from Loop to Wend, then I'm getting the following:
(12, 1) Microsoft VBScript runtime error: Object required: 'cmd'
Thanks for any help.
David
(22, 1) Microsoft VBScript compilation error: 'loop' without 'do'
I changed line 22 from Loop to Wend, then I'm getting the following:
(12, 1) Microsoft VBScript runtime error: Object required: 'cmd'
Thanks for any help.
David
Oh sorry....that's what I get for not testing.....try this.
Regards,
Rob.
Regards,
Rob.
Const ADS_SCOPE_SUBTREE = 2
Dim objRoot, strDNSDomain, objConn, objCommand, objRS
Set objRoot = GetObject("LDAP://RootDSE")
strDNSDomain = "LDAP://" & objRoot.Get("defaultNamingContext")
Set objConn = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConn.Provider = "ADsDSOObject"
objConn.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConn
objCommand.CommandText = "SELECT ADsPath,cn FROM '" & strDNSDomain & "' WHERE mail='*' AND objectClass='group'"
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Timeout") = 300
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
Set objRS = objCommand.Execute
strResults = "Mail enabled groups:"
While Not objRS.EOF
strResults = strResults & VbCrLf & objRS.Fields("cn").Value
objRS.MoveNext
Wend
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objOutput = objFSO.CreateTextFile("MailEnabledGroups.txt", True)
objOutput.Write strResults
objOutput.Close
Set objOutput = Nothing
Set objFSO = Nothing
Set objRS = Nothing
Set objCommand = Nothing
Set objConn = Nothing
Set objDomain = Nothing
Set objRoot = Nothing
MsgBox "Done. Please see MailEnabledGroups.txt"
ASKER
Thank you, that works perfectly. Now, how can I add the display name for each member of each group. I would like the output to appear something like this:
Human Resources John Smith, Pete Wright, Sally Jones
Payroll Denise Smith, Celia Smith
...
...
Thanks,
David
Human Resources John Smith, Pete Wright, Sally Jones
Payroll Denise Smith, Celia Smith
...
...
Thanks,
David
Do you want the output in CSV or Text format?
Rob.
Rob.
ASKER
CSV would be great. Thank you.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you Rob, this is exactly what I needed.
No problem. Thanks for the grade.
Regards,
Rob.
Regards,
Rob.
Regards,
Rob.
Open in new window