Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


Script to export Exchange users default SMTP email address

Script to export Exchange users default SMTP email address

Script to export Exchange users default SMTP email address

Hi All,
Does anyone have a script that could read into AD and export each user default SMTP email address with their full names to an Excel CSV or tab delimited file?

RE: Script to export Exchange users default SMTP email address

below gets it from exchange, we dont populate ad with the upto date information.

ad query would be

strUser = InputBox("Enter your name")

Set user = GetObject("WinNT://domfsc01/" & strUser & ",user")

msgbox user.Profile


but i am not sure what the property for the mail address is


Set WshShell = WScript.CreateObject("WScript.Shell")
Set WshNetwork = WScript.CreateObject("WScript.Network")
Set oCommand = CreateObject("ADODB.Command")
Set oConnection = CreateObject("ADODB.Connection")
oConnection.Provider = "ADsDSOObject"
oConnection.Open = "Active Directory Provider"
oCommand.ActiveConnection = oConnection
oCommand.Properties("Page Size") = 100
oCommand.Properties("Timeout") = 30
oCommand.Properties("Searchscope") = 2
oCommand.Properties("Cache Results") = False

Set oRS = oConnection.Execute("SELECT mail,uid,sn,givenName FROM 'LDAP://abg0970e.abg.fsc.net' WHERE uid='" & WshNetwork.Username & "'")

'While Not oRS.EOF
If oRS.RecordCount = 1 Then                    For i = 0 To oRS.Fields.Count - 1    
        If IsArray(oRS.Fields(i).value) Then
            aArray = oRS.Fields(i).Value
            If oRS.Fields(i).Name = "sn" Then
                strSN = aArray(0)
            ElseIf oRS.Fields(i).Name = "givenName" Then
                strGN = aArray(0)
            End If
            'msgbox oRS.Fields(i).Name & ": " & aArray(0)
            WshShell.RegWrite "HKCU\Software\WASP\NetWorker Laptop_6.2_EN\" & oRS.Fields(i).Name, aArray(0)
            If oRS.Fields(i).Name = "sn" Then
                strSN = oRS.Fields(i)
            ElseIf oRS.Fields(i).Name = "givenName" Then
                strGN = oRS.Fields(i)
            End If

            'msgbox oRS.Fields(i).Name & ": " & oRS.Fields(i)
            WshShell.RegWrite "HKCU\Software\WASP\NetWorker Laptop_6.2_EN\" & oRS.Fields(i).Name, oRS.Fields(i).Value
        End If
    WshShell.RegWrite "HKCU\Software\WASP\NetWorker Laptop_6.2_EN\commonNameNational", strGN & " " & strSN
    WshShell.RegWrite "HKCU\Software\WASP\NetWorker Laptop_6.2_EN\sn", strUserName
    WshShell.RegWrite "HKCU\Software\WASP\NetWorker Laptop_6.2_EN\mail", strUserName & "@fujitsu-siemens.com"
    WshShell.RegWrite "HKCU\Software\WASP\NetWorker Laptop_6.2_EN\commonNameNational", strUserName

End If
Set oRS = Nothing
Set oConnection = Nothing
Set oCommand = Nothing
Set WshNetwork = Nothing
Set WshShell = Nothing  

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close