Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to filter out all the mail-enabled groups?

Posted on 2009-07-13
3
Medium Priority
?
300 Views
Last Modified: 2012-05-07
Hello,

I am looking for a script to list all the mail-enabled groups and export them in an excel sheet.

Thanks
0
Comment
Question by:amyassein
3 Comments
 
LVL 57

Accepted Solution

by:
Mike Kline earned 2000 total points
ID: 24837813
I like adfind by MVP Joe Richards
http://www.joeware.net/freetools/tools/adfind/index.htm

adfind -default -f  "&(objectcategory=group)(mail=*)"  displayname mail -csv -nodn > c:\mailEnabled.csv
That will give you a csv on your C drive.
 
I also helped with a similar question earlier this year
http://www.experts-exchange.com/Database/LDAP/Q_24100116.html
Thanks
Mike
0
 
LVL 27

Expert Comment

by:bluntTony
ID: 24839082
Just for completeness, the below is a simple VB script will produce a report of all mail enabled groups and their location in your domain.

Save as a vbs and run via cscript, e.g:

cscript getAllMailEnabledGroups.vbs

To output to a text file:

cscript getAllMailEnabledGroups.vbs > results.txt

Tony


Set objRoot = GetObject("LDAP://RootDSE")
strBase = "<LDAP://" & objRoot.get("defaultNamingContext") & ">;"
strFilter = "(&(objectclass=group)(mail=*));" 
strAttrs  = "distinguishedName;"
strScope  = "subtree"
 
Set objConn = CreateObject("ADODB.Connection")
Set objComm =   CreateObject("ADODB.Command")
objConn.Provider = "ADsDSOObject"
objConn.Open "Active Directory Provider"
Set objComm.ActiveConnection = objConn
objComm.Properties("Page Size") = 1000
objComm.CommandText = strBase & strFilter & strAttrs & strScope
Set objRS = objComm.Execute
 
If objRs.RecordCount > 0 Then
	objRS.MoveFirst
	Do
		Set objGroup = GetObject("LDAP://" & Replace(objRS.Fields(0).Value,"/","\/"))
		WScript.Echo objGroup.cn & String(40-Len(objGroup.cn)," ") & " : (" & objGroup.distinguishedName & ")"
		objRS.MoveNext
	Loop Until objRS.EOF
End If
 
Set objRoot = Nothing
Set objComm = Nothing
Set objConn = Nothing
Set objGroup = Nothing
Set objRS = Nothing

Open in new window

0
 
LVL 1

Author Comment

by:amyassein
ID: 24848109
bluntTony,

VBScript Runtime Error: "Invalid procedure call or argument: 'String'"

Any ideas?
0

Featured Post

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A hard and fast method for reducing Active Directory Administrators members.
Wouldn't it be nice if objects in Active Directory automatically moved into the correct Organizational Units? This is what AutoAD aims to do and as a plus, it automatically creates Sites, Subnets, and Organizational Units.
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question