Re: Looking for a VB to export all Users and their descripitions



arasaka wrote:

"arasaka" <arasaka@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:870D4C4D-F117-454F-B18F-81C9822BADFC@xxxxxxxxxxxxxxxx
I am looking for a VBscript that will export or Echo all the the users in
the
domain including all sub OUs and the users descripition.

Any ideas?

Hi,

You can use ADO to retrieve all user names and the value of the description
attribute. Tips for doing this linked here:

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

The description attribute is a bit unusual (as explained in the link), as it
is technically multi-valued and ADO returns either a Null (if there is no
value) or a variant array. There is never more than one string value in the
variant array, but it cannot be handled as a normal string. Example below.
This should be run at a command prompt using the cscript host. The output
can be redirected to a text file.
============
Option Explicit

Dim objRootDSE, strDNSDomain, adoCommand, adoConnection
Dim strBase, strFilter, strAttributes, strQuery, adoRecordset
Dim strNTName, lngUSN, strDescription, colDescription, strItem

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

' Use ADO to search Active Directory.
Set adoCommand = CreateObject("ADODB.Command")
Set adoConnection = CreateObject("ADODB.Connection")
adoConnection.Provider = "ADsDSOObject"
adoConnection.Open "Active Directory Provider"
adoCommand.ActiveConnection = adoConnection

' Search entire domain.
strBase = "<LDAP://"; & strDNSDomain & ">"

' Filter on all user objects.
strFilter = "(&(objectCategory=person)(objectClass=user))"

' Comma delimited list of attribute values to retrieve.
strAttributes = "sAMAccountName,description"

' Construct the LDAP query.
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"

adoCommand.CommandText = strQuery
adoCommand.Properties("Page Size") = 100
adoCommand.Properties("Timeout") = 30
adoCommand.Properties("Cache Results") = False
Set adoRecordset = adoCommand.Execute

' Enumerate the resulting recordset.
Do Until adoRecordset.EOF
' Retrieve values.
strNTName = adoRecordset.Fields("sAMAccountName").Value
colDescription = adoRecordset.Fields("description").Value
' Value of description is either Null or a variant array.
If IsNull(colDescription) Then
strDescription = ""
Else
For Each strItem In colDescription
strDescription = strItem
Next
End If
Wscript.Echo strNTName & ", " & strDescription
adoRecordset.MoveNext
Loop
adoRecordset.Close
adoConnection.Close

' Clean up.
Set objRootDSE = Nothing
Set adoCommand = Nothing
Set adoConnection = Nothing
Set adoRecordset = Nothing

--
Richard
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net


.



Relevant Pages

  • Re: On ADSI and LDAP
    ... the problem is how can I retrieve the value for myuser using the ... would be more efficient to use ADO to query AD for the attributes values. ... For more on using ADO, ... Dim adoCommand, adoConnection, strBase, strFilter, strAttributes ...
    (microsoft.public.scripting.vbscript)
  • Re: Returning only a subset of groups in AD
    ... Output.WriteLine "There are no members in this group." ... I assume that ADSICommand is an ADO command object, ... value assigned to the CommandText property, which is the ADO query. ... ' Comma delimited list of attribute values to retrieve. ...
    (microsoft.public.scripting.vbscript)
  • Re: Scripting newbie - Active Directory reporting of users/description
    ... Does any one have a sample script that looks at an Active Directory ... You can use ADO in a VBScript program to retrieve information about objects ...
    (microsoft.public.windows.server.scripting)
  • Re: How to change script to run thru multiple objects
    ... you can use ADO to retrieve information on all users in AD (or ... you must retrieve attribute values. ... In this case the PasswordLastChanged property method converts the ... WScript.Echo "The password does not expire." ...
    (microsoft.public.scripting.vbscript)

Loading