Re: Looking for a VB to export all Users and their descripitions
- From: "Richard Mueller" <rlmueller-NOSPAM@xxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 7 Jul 2006 11:06:22 -0500
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
.
- Prev by Date: Re: Convert objectSID to string
- Next by Date: Re: ADAMSync Issues.
- Previous by thread: find out who has access to make changes to AD (ie. delete or create OU's
- Next by thread: Re: Looking for a VB to export all Users and their descripitions
- Index(es):
Relevant Pages
|
Loading