Re: List all email addresses in AD

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



On Thu, 25 May 2006 15:01:24 -0700, Villain <jdsauer@[not.giving.you]>
wrote:

Hello,

~snip~

Anyways.. I was wondering if anyone knew of a script that would give
me the following information:

username
email_address_1
email_address_2
etc.

username
email_address_1

~snip~

Thanks again,

Villain


Here is the code that I found, is there something that would cause the
problem? Is there a change that I should make to it?



Option Explicit

Dim strFilePath, strLdapPath, objFSO, objFile, objConnection, objChild

' Check all arguments required have been passed
If Wscript.Arguments.Count < 2 Then
Wscript.Echo "Arguments <Root DN> <FileName> required. For example:" &
vbCrLf _
& "cscript listuserswithemail.vbs ou=test,dc=demo,dc=test
c:\temp\UserList.txt"
Wscript.Quit(0)
End If

strLdapPath = Wscript.Arguments(0)

strFilePath = Wscript.Arguments(1)

Set objFSO = CreateObject("Scripting.FileSystemObject")


' Open the file for write access.
On Error Resume Next
Set objFile = objFSO.OpenTextFile(strFilePath, 2, True, 0)
If Err.Number <> 0 Then
On Error GoTo 0
Wscript.Echo "File " & strFilePath & " cannot be opened"
Wscript.Quit(1)
End If
On Error GoTo 0

Set objConnection = GetObject("LDAP://"; & strLdapPath)
objConnection.Filter = Array("user")

For Each objChild In objConnection
WScript.Echo objChild.Name & vbTab & objChild.givenName & " " &
objChild.sn & " " & objChild.mail
objFile.WriteLine objChild.givenName & "|" & objChild.sn & "|" &
objChild.mail
Next

' Close file connection
objFile.Close

Wscript.Echo "Operation Completed"

.



Relevant Pages

  • Re: WSH Error when running script
    ... I am sorry let me explain further what I am wanting is a more dynamic script ... based only on their username. ... On Error GoTo 0 ... ' Temporarily suspend normal error handling. ...
    (microsoft.public.windows.server.scripting)
  • Re: WSH Error when running script
    ... You could use something similar to below to trap the error raised if drive ... On Error GoTo 0 ... The UserName property of the WSHNetwork object can return ... ' Temporarily suspend normal error handling. ...
    (microsoft.public.windows.server.scripting)
  • Re: WSH Error when running script
    ... You could have one If Then/End If structure for each UserName. ... ' Subroutine to map a drive to a share. ... On Error GoTo 0 ... ' Temporarily suspend normal error handling. ...
    (microsoft.public.windows.server.scripting)
  • Re: How do I insert different pictures using and If statement in Word.
    ... > You can put INCLUDEPICTURE fields in the results of an IF ... SNIP> ... reason. ... I thought maybe because the USERNAME has a space in the middle? ...
    (microsoft.public.word.mailmerge.fields)
  • Re: Programming a router - thank you
    ... Alex Cessford wrote: ... <Snip my own stuff> ... new username as well), and was I ok with that. ... Eg. a 'paint-by-numbers' list of instructions, ...
    (comp.sys.acorn.hardware)