No announcement yet.

Autofilling email address in AD

  • Filter
  • Time
  • Show
Clear All
new posts

  • Autofilling email address in AD


    We have been asked at work by auditors to ensure that all users in AD have the email address field filled. On running a query we have found that about 400/500 people have not the email address filled in.

    Is it possible to run a script or run something in AD to automatically fill all users email address field. We use Lotus Notes so unfortunately we don't use Exchange.

    Any help is greatly appreciated.


  • #2
    Re: Autofilling email address in AD

    Hey there,

    this all depends on what your email address naming convention is.
    is it something like [email protected] ?
    as long as its consistant a script for this is pretty easy.
    as the email is just a AD field, you could do this with powershell or a simple script.


    • #3
      Re: Autofilling email address in AD

      You can use ADModify to make bulk changes to users.


      • #4
        Re: Autofilling email address in AD

        Hi Guys,

        Apologies for the late reply, i was out of work last week. Appreciate the comments. I have created the below scriptfrom one i found online but have been unsuccessful in running it due to some errors coming up. I'm no programmer or script writer so having trouble deciphering the problem. Also, in answer to your question joshsaunders, yes it is consistent, it's [email protected].

        On Error Resume Next

        Const ADS_SCOPE_SUBTREE = 2
        Set objConnection = CreateObject("ADODB.Connection")
        Set objCommand = CreateObject("ADODB.Command")
        objConnection.Provider = "ADsDSOObject"
        objConnection.Open "Active Directory Provider"
        Set objCommand.ActiveConnection = objConnection
        objCommand.Properties("Page Size") = 1000
        objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
        objCommand.CommandText = _
        "SELECT AdsPath,givenName,userPrincipalName FROM " & _
        "'LDAP://OU=TestOU,dc=AP,dc=com' WHERE objectCategory='user'"
        objCommand.CommandText = _
        "SELECT AdsPath,sn,userPrincipalName FROM " & _
        "'LDAP://OU=TestOU,dc=AP,dc=com' WHERE objectCategory='user'"
        Set objRecordSet = objCommand.Execute
        Do Until objRecordSet.EOF
        strUser = objRecordSet.Fields("ADsPath").Value
        strNewUPN = objRecordSet.Fields("givenName").Value & "_" & objRecordSet.Fields("sn").Value & "@" & ""
        Set objUser = GetObject(strUser)
        objUser.Mail = strNewUPN

        Thanks again Guys for any help given

        Kind Regards