Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Script to export Exchange users default SMTP email address

Status
Not open for further replies.

lengoo

IS-IT--Management
Jan 15, 2002
381
GH
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?
Thanks
 
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)
Else
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
Next
'oRS.MoveNext
WshShell.RegWrite "HKCU\Software\WASP\NetWorker Laptop_6.2_EN\commonNameNational", strGN & " " & strSN
Else

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
'Wend

Set oRS = Nothing
Set oConnection = Nothing
Set oCommand = Nothing
Set WshNetwork = Nothing
Set WshShell = Nothing
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top