The mail attribute is not exposed by the WinNT provider. You will need to
use the LDAP provider. You can use ADO to retrieve the value of this
attribute for all users in your domain in a VBScript program. VB would be
very similar. For example:
=============
Option Explicit
Dim adoCommand, adoConnection, strBase, strFilter, strAttributes
Dim strQuery, adoRecordset, strName, strMail
' Setup ADO objects.
Set adoCommand = CreateObject("ADODB.Command")
Set adoConnection = CreateObject("ADODB.Connection")
adoConnection.Provider = "ADsDSOObject"
adoConnection.Open "Active Directory Provider"
adoCommand.ActiveConnection = adoConnection
' Search entire Active Directory domain.
strBase = "<LDAP://dc=MyDomain,dc=com>"
' Filter on user objects.
strFilter = "(&(objectCategory=person)(objectClass=user))"
' Comma delimited list of attribute values to retrieve.
strAttributes = "sAMAccountName,mail"
' Construct the LDAP syntax query.
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
adoCommand.CommandText = strQuery
adoCommand.Properties("Page Size") = 100
adoCommand.Properties("Timeout") = 30
adoCommand.Properties("Cache Results") = False
' Run the query.
Set adoRecordset = adoCommand.Execute
' Enumerate the resulting recordset.
Do Until adoRecordset.EOF
' Retrieve values and display.
strName = adoRecordset.Fields("sAMAccountName").Value
strMail = adoRecordset.Fields("mail").value
Wscript.Echo "NT Name: " & strName & ", Email: " & strMail
' Move to the next record in the recordset.
adoRecordset.MoveNext
Loop
adoRecordset.Close
adoConnection.Close
=========
For more on using ADO to retrieve attribute values see this link:
http://www.rlmueller.net/ADOSearchTips.htm
--
Richard
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
Post by itmanagerThanks for the reponse. Would you have an example of how to do that?
Dim dom As Object = GetObject("WinNT://" & domain)
For Each o As Object In dom
If CType(o.Class, String).ToLower = "user" Then
Dim name As String = o.Name
Dim fullName As String = o.FullName
End If
Next
Post by Joe KaplanYou need to read the mail attribute. You can definitely do that with ADSI
or .NET (which uses ADSI under the hood if you are talking about
System.DirectoryServices).
Joe K.
--
Joe Kaplan-MS MVP Directory Services Programming
Co-author of "The .NET Developer's Guide to Directory Services Programming"
http://www.directoryprogramming.net
--
Is it possible to retrieve a domain user's email address (for Windows
2003)
using ADSI? We are able to get pretty much all other information except
that.
If it is possible, an example would be much appreciated. If not, do we
need
to use .NET?