George said:
Is there anyway to export ot an excel file a listing of all activer user
accounts and selected propertiesfrom active directory?
Hi,
A sample VBScript program that exports the Distinguished Names of all users
to a spreadsheet is linked here:
http://www.rlmueller.net/Create User List 3.htm
To restrict this to active users, it depends on what you mean by active. To
include only users that are not disabled, replace this statement in the
program:
strFilter = "(&(objectCategory=person)(objectClass=user))"
with the following:
strFilter = "(&(objectCategory=person)(objectClass=user)" _
& "(!userAccountControl:1.2.840.113556.1.4.803:=2))"
To retrieve more attributes, add to the comma delimited list of attributes.
For example, replace:
strQuery = "<LDAP://" & strDNSDomain & ">;" & strFilter _
& ";distinguishedName;subtree"
with:
strQuery = "<LDAP://" & strDNSDomain & ">;" & strFilter _
& ";distinguishedName,sAMAccountName,cn,displayName;subtree"
Then, you in the loop that enumerates users, retrieve the new attribute
values with statements similar to the ones for Distinguished Name. Then
write the values to cells in new columns of the spreadsheet. For example,
replace:
Do Until objRecordSet.EOF
strDN = objRecordSet.Fields("distinguishedName")
objSheet.Cells(k, 1).Value = strDN
k = k + 1
objRecordSet.MoveNext
Loop
With:
' Declare new variables.
Dim strNTName, strCN, strDisplayName
Do Until objRecordSet.EOF
strDN = objRecordSet.Fields("distinguishedName")
strNTName = objRecordset.Fields("sAMAccountName")
strCN = objRecordset.Fields("cn")
strDisplayName = objRecordset.Fields("displayName")
objSheet.Cells(k, 1).Value = strDN
objSheet.Cells(k, 2).Value = strNTName
objSheet.Cells(k, 3).Value = strCN
objSheet.Cells(k, 4).Value = strDisplayName
k = k + 1
objRecordSet.MoveNext
Loop
Also, note that any script or utility that outputs attribute values in a
comma delimited format can be used. Either specify an export file or
redirect the output to a text file. This file can be imported into a
spreadsheet. The utility csvde, for example, can export attribute values to
a comma delimited text file that can be imported into a spreadsheet. Get
help for csvde at the command prompt of a Domain Controller.