Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - Export user information in txt file?

Reply
 
Old 10-08-2009   #1 (permalink)
Ruben Gardenier


 
 

Export user information in txt file?

Hi there,

I'm pretty new to vbs script, so I would like to know if it's possible to
export user information (such as displayname, e-mail) from our active
directory
based on a comma based txt file with only the username

Thnx,
Ruben

My System SpecsSystem Spec
Old 10-08-2009   #2 (permalink)
Paul Randall


 
 

Re: Export user information in txt file?


"Ruben Gardenier" <RubenGardenier@newsgroup> wrote in
message news:41C42B85-3204-45BC-8701-2FAF4EF55FAD@newsgroup
Quote:

> Hi there,
>
> I'm pretty new to vbs script, so I would like to know if it's possible to
> export user information (such as displayname, e-mail) from our active
> directory
> based on a comma based txt file with only the username

Google is your friend, and Groups.Google.Com is even better than plain
Google when it comes to finding info of interest that might have been
discussed in some particular newsgroup. Problems similar to yours have been
discussed often in this newsgroup and there are references to web sites with
info that might be useful to you.

Go to Groups.Google.Com and navigate through the advanced group search,
putting in some key words to search for and
microsoft.public.scripting.vbscript as the newsgroup of interest, or just
paste the following into the search box:
user information active directory username group:*.scripting.vbscript

You will find lots of potentially helpful links and after reading some of
them you will probably realize that perhaps going to Richard Mueller's
website, http://www.rlmueller.net, might lead you to a script that does very
close to what you want, with helpful explainations along the way.

-Paul Randall


My System SpecsSystem Spec
Old 10-08-2009   #3 (permalink)
Richard Mueller [MVP]


 
 

Re: Export user information in txt file?


"Ruben Gardenier" <RubenGardenier@newsgroup> wrote in
message news:41C42B85-3204-45BC-8701-2FAF4EF55FAD@newsgroup
Quote:

> Hi there,
>
> I'm pretty new to vbs script, so I would like to know if it's possible to
> export user information (such as displayname, e-mail) from our active
> directory
> based on a comma based txt file with only the username
>
> Thnx,
> Ruben
Here is an example that documents all users to a comma delimited file:

http://www.rlmueller.net/DocumentUsers.htm

The example demonstrates how to handle a variety of attribute formats, but
you should be able to modify this for your needs. You want the displayName
attribute, and for email either the mail attribute, which a single valued
string, or the proxyAddresses attribute (if you use Exchange), which is a
multi-valued string attribute.

If instead of all users you want to document those listed in a text file,
then you can use the FileSystemObject to read the file one line at a time.
Easiest would be to have a text file of Distinguished Names, so you can bind
to each user object directly. If instead you have a file of pre-Windows 2000
logon names, then you can use the NameTranslate object to convert to
Distinguished Names. See this link for how to use the NameTranslate object:

http://www.rlmueller.net/NameTranslateFAQ.htm

An example that documents sAMAccountName, displayName, and mail might be
similar to:
=================
Const ForReading = 1
' Constants for the NameTranslate object.
Const ADS_NAME_INITTYPE_GC = 3
Const ADS_NAME_TYPE_NT4 = 3
Const ADS_NAME_TYPE_1779 = 1

' Determine DNS name of domain from RootDSE.
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("defaultNamingContext")

' Use the NameTranslate object to find the NetBIOS domain name from the
' DNS domain name.
Set objTrans = CreateObject("NameTranslate")
objTrans.Init ADS_NAME_INITTYPE_GC, ""
objTrans.Set ADS_NAME_TYPE_1779, strDNSDomain
strNetBIOSDomain = objTrans.Get(ADS_NAME_TYPE_NT4)
' Remove trailing backslash.
strNetBIOSDomain = Left(strNetBIOSDomain, Len(strNetBIOSDomain) - 1)

' Specify the text file of user names.
strFilePath = "c:\Scripts\UserList.txt"

' Open the file for read access.
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(strFilePath, ForReading)

' Read user names from file.
Do Until objFile.AtEndOfStream
strName = Trim(objFile.ReadLine)
' Skip blank lines.
If (strName <> "") Then
' Use the Set method to specify the NT format of the name.
' Trap error if user does not exist.
On Error Resume Next
objTrans.Set ADS_NAME_TYPE_NT4, strNetBIOSDomain & "\" & strName
If (Err.Number = 0) Then
On Error GoTo 0
' Use the Get method to retrieve the Distinguished Name.
strUserDN = objTrans.Get(ADS_NAME_TYPE_1779)
' Bind to user object.
Set objUser = GetObject("LDAP://" & strUserDN)
' Output attribute values, comma delimited.
' Enclose displayName in quotes because it could have spaces.
Wscript.Echo objUser.sAMAccountName & ",""" _
& objUser.displayName & """," & objUser.mail
Else
On Error GoTo 0
Call MsgBox("User " & strName & " not found")
End If
End If
Loop

' Clean up.
objFile.Close
==========
This program is designed to echo to a command prompt, so you would redirect
the output to a text file. You can also use the FileSystemObject to open a
second file for write access and use the WriteLine method to write the
output directly to the file. The above example binds to each user object,
which slows the script and is less efficient than using ADO to query all at
once. Still, this would make sense if you want to document only a small
subset of all users.

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--


My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
User Agent information for ie 8 Browsers & Mail
Hidden user account information Vista General
copy file dialog with file information? Vista General
HKEY_USERS -- Does it have information for each user? Vista file management
Export-CliXml/Export-Csv: Change to Export-Object? PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46