Solved

Validate SMTP address in Exchange2003/AD

Posted on 2007-03-30
5
350 Views
Last Modified: 2008-05-31
We are creating user accounts/mailboxes in AD 2003/Exchange 2003 with ADSI-scripting (VB-script). We also want to set an SMTP address during/after creation and NOT use RUS to automatically set an address. Is there a way to validate an SMTP address before setting it? I know we can loop "ProxyAddresses", but it feels time- and resource consuming. When using for instance "Active Directory Users and Copmputers" to set an SMTP address, a validation is done...
0
Comment
Question by:itsupportoll
  • 2
5 Comments
 
LVL 70

Expert Comment

by:Chris Dent
ID: 18825679

Validation by script is slow, there isn't much of a way around that. You can play around with the different methods of doing it of course, but none are especially quick.

AD Users and Computers can, of course, do this much more quickly because it's not limited by a scripting language. If you were to code and compile a .NET application (for example) you would find any validation would be considerably faster than anything you can do in a script.

We could always try and suggest ways to make what you're doing more efficient. How are you thinking of validating addresses at the moment?

Chris
0
 

Author Comment

by:itsupportoll
ID: 18826829
Well, we don't have  to do the validation with a script, of course we are open to a better solution. Is there open source code to compile a application or similar, that's ok with us. Our current situation is that we will use our personell system to "correct" the data in AD/Exchange with correct information. We have approximately 10 000 users. It's not a "one-time-operation", we will continue to transfer data/smtp addresses from our personell system. Since we still are in the development/testing stadium, all bright ideas are welcome to solve this the best way.
0
 
LVL 70

Accepted Solution

by:
Chris Dent earned 500 total points
ID: 18834844

For us the easiest way to handle validation like this was in this order:

1. Open data connection to external system and read data into Scripting.Dictionary object.
 - If it isn't convenient to configure this list with the SMTP address as the Key then create a second list with <SMTPAddress>, <Key> so they can be very easily linked.

2. Run an AD Query and handle any address that already exists in AD. In my case this is simply a case of discarding them from the imported data (necessity of the design). It logs this using a WriteLog subroutine and counts them with intDiscarded.

Const ADS_SCOPE_SUBTREE = 2

Set objConnection = CreateObject("ADODB.Connection")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"

Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection

Set objRootDSE = GetObject("LDAP://RootDSE")
objCommand.CommandText = "SELECT displayName, aDSPath, proxyAddresses " &_
      "FROM 'GC://" & objRootDSE.Get("rootDomainNamingContext") & "'"
Set objRootDSE = Nothing

objCommand.Properties("Page Size") = 1000
objCommand.Properties("Timeout") = 600
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.Properties("Cache Results") = False

Set objRecordSet = objCommand.Execute

While Not objRecordSet.EOF
      If Not IsNull(objRecordSet.Fields("proxyAddresses")) Then
            arrAddresses = objRecordSet.Fields("proxyAddresses")
                  
            For Each strAddress in arrAddresses
                  If InStr(1, strAddress, "smtp:", VbTextCompare) Then
                        strAddress = LCase(Replace(strAddress, "smtp:", "", 1, -1, 1))
                        If objData.Exists(strAddress) Then
                              WriteLog "Duplicate Email Address Found:", True
                              WriteLog "Removed: " & strAddress & ": " & objData(strAddress)(0) & " " &_
                                    objData(strAddress)(1) & "; " & objData(strAddress)(2), True
                              WriteLog "Existing Address On: " & objRecordSet.Fields("aDSPath"), True
                              objData.Remove strAddress
                              intDiscarded = intDiscarded + 1
                        End If
                  End If
            Next
      End If
            objRecordSet.MoveNext
Wend
objConnection.Close

Set objRecordSet = Nothing
Set objCommand = Nothing
Set objConnection = Nothing

3. Run normal processes for remaining data.


How useful that kind of solution is depends entirely on how the program runs, if it does masses of data with a relatively low frequency then a minute or so getting every address in the domain is moderately acceptable.

However, if it does a user or two every few minutes then that places a very high load on the script. Let me see if I can build an application and see how quickly that returns.

Chris
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
While rebooting windows server 2003 server , it's showing "active directory rebuilding indices please wait" at startup. It took a little while for this process to complete and once we logged on not all the services were started so another reboot is …
In this video we show how to create a mailbox database in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Servers >> Data…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

785 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