Link to home
Start Free TrialLog in
Avatar of amyassein
amyassein

asked on

How to filter out all the mail-enabled groups?

Hello,

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

Thanks
ASKER CERTIFIED SOLUTION
Avatar of Mike Kline
Mike Kline
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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

Avatar of amyassein
amyassein

ASKER

bluntTony,

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

Any ideas?