Hi All:
I would like to retrieve users info from Active Directory
and write the output to a CVS file, most important vlaue
now is the email e.g user@myorg.com

Thanks

Re: Readin info by Richard

Richard
Tue Sep 02 10:28:06 CDT 2003

Hi,

With the statement "On Error Resume Next" you will not get error messages,
so you will be unable to tell if any statements raise errors. For example,
the "Set objUser" statement may raise errors if the binding string is
incorrect. Or, the user may have no value for the "mail" attribute, in which
case the objUser.Get method will raise an error. In both cases, the variable
strmail will be an empty string.

If you want the script to handle the situation where the "mail" attribute
has no value, I would suggest using:

Set objUser = GetObject _
("LDAP://cn=***,ou=***,ou=***,dc=***,dc=***")

strmail = objUser.mail
Wscript.Echo "mail: " & strmail

If the "mail" attribute has no value, the variable strmail will be a blank
string, but no error will be raised. The Put method raises an error when the
attribute has no value. If the binding string is wrong, you want the "Set
objUser" statement to raise an error so you know about it and can fix it.

--
Richard
Microsoft MVP Scripting and ADSI
HilltopLab web site - http://www.rlmueller.net
--

"Amer" <amir@orocn.co.nz> wrote in message
news:eonWpjScDHA.2580@TK2MSFTNGP12.phx.gbl...
> Hi:
> Thanks for that.
> But
> All what I get a WSH box with word mail:
> that's it.
> Am I doing something wrong?
>
> I am using this (Still Junior)
>
>
> On Error Resume Next
> Set objUser = GetObject _
> ("LDAP://cn=***,ou=***,ou=***,dc=***,dc=***")
> objUser.GetInfo
>
> strmail = objUser.Get ("mail")
> Wscript.Echo "mail: " & strmail
> cscript filename.vbs >> c:\scripts\filename.csv
>
>
> "Richard Mueller [MVP]" <rlmueller@ameritech.net> wrote in message
> news:OKZWj20bDHA.656@tk2msftngp13.phx.gbl...
> > Amer wrote:
> >
> > > I would like to retrieve users info from Active Directory
> > > and write the output to a CVS file, most important vlaue
> > > now is the email e.g user@myorg.com
> >
> > Hi,
> >
> > The best way to retrieve info for all users in AD is to use ADO. The
> > attribute for the email address is "mail". You could retrieve other
> > attributes as well. This should work to dump all user NT Names
> > (sAMAccountName, or "pre-Windows 2000 logon name") and email address to
a
> > comma delimited file, one user per line:
> >
> > ======== VBScript program ===========
> > Option Explicit
> > Dim objRootDSE, strDNSDomain, objCommand, objConnection
> > Dim strBase, strFilter, strAttributes, strQuery, objRecordSet
> > Dim strNTName, strEMail
> >
> > ' Determine DNS domain name.
> > Set objRootDSE = GetObject("LDAP://RootDSE")
> > strDNSDomain = objRootDSE.Get("defaultNamingContext")
> >
> > ' Use ADO to search Active Directory.
> > Set objCommand = CreateObject("ADODB.Command")
> > Set objConnection = CreateObject("ADODB.Connection")
> > objConnection.Provider = "ADsDSOObject"
> > objConnection.Open "Active Directory Provider"
> > objCommand.ActiveConnection = objConnection
> > strBase = "<LDAP://" & strDNSDomain & ">"
> >
> > strFilter = "(&(objectCategory=person)(objectClass=user))"
> > strAttributes = "sAMAccountName,mail"
> > strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
> > objCommand.CommandText = strQuery
> > objCommand.Properties("Page Size") = 100
> > objCommand.Properties("Timeout") = 30
> > objCommand.Properties("Cache Results") = False
> > Set objRecordSet = objCommand.Execute
> >
> > Do Until objRecordSet.EOF
> > strNTName = objRecordSet.Fields("sAMAccountName")
> > strEMail = objRecordSet.Fields("mail")
> > Wscript.Echo strNTName & ", " & strEMail
> > objRecordSet.MoveNext
> > Loop
> >
> > ' Clean up.
> > objConnection.Close
> > Set objRootDSE = Nothing
> > Set objCommand = Nothing
> > Set objConnection = Nothing
> > Set objRecordSet = Nothing
> > =========================
> >
> > This program outputs to the command line, so you can re-direct the
output
> to
> > a file. For example, at a command prompt, if the VBScript file is called
> > GetEMail.vbs, run the program with:
> >
> > cscript //nologo GetEMail.vbs > MyDomain.csv
> >
> > --
> > Richard
> > Microsoft MVP Scripting and ADSI
> > HilltopLab web site - http://www.rlmueller.net
> > --
> >
> >
>
>



Re: Readin info by Amer

Amer
Wed Sep 03 05:50:21 CDT 2003

Thanks
I will try that.

Thanks a lot
"Richard Mueller [MVP]" <rlmueller@ameritech.net> wrote in message
news:uU5GibWcDHA.1808@TK2MSFTNGP11.phx.gbl...
> Hi,
>
> With the statement "On Error Resume Next" you will not get error messages,
> so you will be unable to tell if any statements raise errors. For example,
> the "Set objUser" statement may raise errors if the binding string is
> incorrect. Or, the user may have no value for the "mail" attribute, in
which
> case the objUser.Get method will raise an error. In both cases, the
variable
> strmail will be an empty string.
>
> If you want the script to handle the situation where the "mail" attribute
> has no value, I would suggest using:
>
> Set objUser = GetObject _
> ("LDAP://cn=***,ou=***,ou=***,dc=***,dc=***")
>
> strmail = objUser.mail
> Wscript.Echo "mail: " & strmail
>
> If the "mail" attribute has no value, the variable strmail will be a blank
> string, but no error will be raised. The Put method raises an error when
the
> attribute has no value. If the binding string is wrong, you want the "Set
> objUser" statement to raise an error so you know about it and can fix it.
>
> --
> Richard
> Microsoft MVP Scripting and ADSI
> HilltopLab web site - http://www.rlmueller.net
> --
>
> "Amer" <amir@orocn.co.nz> wrote in message
> news:eonWpjScDHA.2580@TK2MSFTNGP12.phx.gbl...
> > Hi:
> > Thanks for that.
> > But
> > All what I get a WSH box with word mail:
> > that's it.
> > Am I doing something wrong?
> >
> > I am using this (Still Junior)
> >
> >
> > On Error Resume Next
> > Set objUser = GetObject _
> > ("LDAP://cn=***,ou=***,ou=***,dc=***,dc=***")
> > objUser.GetInfo
> >
> > strmail = objUser.Get ("mail")
> > Wscript.Echo "mail: " & strmail
> > cscript filename.vbs >> c:\scripts\filename.csv
> >
> >
> > "Richard Mueller [MVP]" <rlmueller@ameritech.net> wrote in message
> > news:OKZWj20bDHA.656@tk2msftngp13.phx.gbl...
> > > Amer wrote:
> > >
> > > > I would like to retrieve users info from Active Directory
> > > > and write the output to a CVS file, most important vlaue
> > > > now is the email e.g user@myorg.com
> > >
> > > Hi,
> > >
> > > The best way to retrieve info for all users in AD is to use ADO. The
> > > attribute for the email address is "mail". You could retrieve other
> > > attributes as well. This should work to dump all user NT Names
> > > (sAMAccountName, or "pre-Windows 2000 logon name") and email address
to
> a
> > > comma delimited file, one user per line:
> > >
> > > ======== VBScript program ===========
> > > Option Explicit
> > > Dim objRootDSE, strDNSDomain, objCommand, objConnection
> > > Dim strBase, strFilter, strAttributes, strQuery, objRecordSet
> > > Dim strNTName, strEMail
> > >
> > > ' Determine DNS domain name.
> > > Set objRootDSE = GetObject("LDAP://RootDSE")
> > > strDNSDomain = objRootDSE.Get("defaultNamingContext")
> > >
> > > ' Use ADO to search Active Directory.
> > > Set objCommand = CreateObject("ADODB.Command")
> > > Set objConnection = CreateObject("ADODB.Connection")
> > > objConnection.Provider = "ADsDSOObject"
> > > objConnection.Open "Active Directory Provider"
> > > objCommand.ActiveConnection = objConnection
> > > strBase = "<LDAP://" & strDNSDomain & ">"
> > >
> > > strFilter = "(&(objectCategory=person)(objectClass=user))"
> > > strAttributes = "sAMAccountName,mail"
> > > strQuery = strBase & ";" & strFilter & ";" & strAttributes &
";subtree"
> > > objCommand.CommandText = strQuery
> > > objCommand.Properties("Page Size") = 100
> > > objCommand.Properties("Timeout") = 30
> > > objCommand.Properties("Cache Results") = False
> > > Set objRecordSet = objCommand.Execute
> > >
> > > Do Until objRecordSet.EOF
> > > strNTName = objRecordSet.Fields("sAMAccountName")
> > > strEMail = objRecordSet.Fields("mail")
> > > Wscript.Echo strNTName & ", " & strEMail
> > > objRecordSet.MoveNext
> > > Loop
> > >
> > > ' Clean up.
> > > objConnection.Close
> > > Set objRootDSE = Nothing
> > > Set objCommand = Nothing
> > > Set objConnection = Nothing
> > > Set objRecordSet = Nothing
> > > =========================
> > >
> > > This program outputs to the command line, so you can re-direct the
> output
> > to
> > > a file. For example, at a command prompt, if the VBScript file is
called
> > > GetEMail.vbs, run the program with:
> > >
> > > cscript //nologo GetEMail.vbs > MyDomain.csv
> > >
> > > --
> > > Richard
> > > Microsoft MVP Scripting and ADSI
> > > HilltopLab web site - http://www.rlmueller.net
> > > --
> > >
> > >
> >
> >
>
>