The best way to get rid off that monday morning feeling is to make a new script…..
Today’s script searches Active Directory for users or resource accounts with multiple smtp addresses.
By changing the treshold value (i) in line number 39 you can broaden or narrow your searches.

Follow the next steps to run the script (no admin rights needed):

* open your favorite text editor
* copy and paste the script into the editor
* save the script (for example c:\temp\showmultiplesmtp.vbs)
* open a command prompt
* go to “c:\temp”
* give “cscript showmultiplesmtp.vbs” (without quotes) and enter

The script:

' Name : showmultiplesmtp.vbs
' Description : script to show all users with multiple smtp addresses
' Author : dirk adamsky - deludi bv
' Version : 1.00
' Date : 22-02-2010
' Level : intermediate

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

Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("defaultNamingContext")
strBase = "<LDAP://" & strDNSDomain & ">"

strFilter = "(&(objectCategory=person)(objectClass=user)(mail=*))"
strAttributes = "distinguishedName"

strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
adoCommand.CommandText = strQuery
adoCommand.Properties("Page Size") = 100
adoCommand.Properties("Timeout") = 30
adoCommand.Properties("Cache Results") = False

Set adoRecordset = adoCommand.Execute

Do Until adoRecordset.EOF
	On Error Resume Next
	Set objUser = GetObject ("LDAP://" & adoRecordset.Fields("distinguishedName").Value)
	arrProxy = objUser.GetEx("proxyAddresses")
	i = 0
	For Each strMailAddress in arrProxy
		If Lcase(Left(strMailAddress,5))= "smtp:" Then
			i = i + 1
		End If
	Next
	If i >= 4 Then
		strAllMailAddresses = ""
		For Each strMailAddress in arrProxy
			If Lcase(Left(strMailAddress,5))= "smtp:" Then
				strAllMailAddresses = strAllMailAddresses & " ; "  & strMailAddress
			End If
		Next
		Wscript.Echo objUser.DisplayName & strAllMailAddresses
	End If
	Set objUser = Nothing
	adoRecordset.MoveNext
Loop

adoRecordset.Close
adoConnection.Close

Set adoRecordset = Nothing
Set objRootDSE = Nothing
Set adoConnection = Nothing
Set adoCommand = Nothing

When you have problems/questions please post a reply.

Happy scripting.

Best regards,

Dirk Adamsky – Deludi BV

VN:F [1.9.3_1094]
Rating: 8.0/10 (1 vote cast)
VN:F [1.9.3_1094]
Rating: 0 (from 0 votes)

Forwarding of email is a very common practice.
In active directory this is an easy task.
Unfortunately aduc is not very good at reporting which accounts have forwarding enabled.
This script enumerates all accounts with forwarding enabled and the smtp addresses where the mails are sent.

Follow the next steps (no admin rights needed):

  • open your favorite text editor
  • copy and paste the script into the editor
  • save the script (for example c:\temp\forwarding.vbs)
  • open a command prompt
  • go to “c:\temp”
  • give “cscript forwarding.vbs” (without quotes) and enter

The script:

' Name : forwarding.vbs
' Description : script to find all accounts with forwarding enabled
' Author : dirk adamsky - deludi bv
' Version : 1.00
' Date : 25-01-2010

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

Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("defaultNamingContext")
strBase = "<LDAP://" & strDNSDomain & ">"
strFilter = "(&(objectCategory=*)(altRecipient=*))"
strAttributes = "displayname, altRecipient"

strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
adoCommand.CommandText = strQuery
adoCommand.Properties("Page Size") = 100
adoCommand.Properties("Timeout") = 30
adoCommand.Properties("Cache Results") = False

Set objRecordset = adoCommand.Execute

objRecordSet.MoveFirst
i = 0
Do Until objRecordSet.EOF
	On Error Resume Next
	i = i + 1
	Set objContact = GetObject("LDAP://" & objRecordSet.Fields("altRecipient").Value)
	Wscript.Echo i & " " & objRecordSet.Fields("displayname").Value & " ; forwarded to ; " & objContact.mail
	Set objContact = Nothing
	objRecordSet.MoveNext
Loop

Set objRecordset = Nothing
Set objRootDSE = Nothing
Set adoConnection = Nothing
Set adoCommand = Nothing
VN:F [1.9.3_1094]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.3_1094]
Rating: 0 (from 0 votes)
© 2010 Dirk Adamsky Scripting Blog Suffusion WordPress theme by Sayontan Sinha