Exporting a list of details from Active Directory
April 7, 2005 12:00 AM   Subscribe

Is there an easy way to export a list of user accounts / details from Active Directory (Windows Server 2003) preferably in a html format like the Group Policy Management reports?
posted by Leud to Technology (2 answers total)
 
Yes, Active Directory speaks LDAP fluently, so you can use any standard LDAP tool (or write your own) to export it's contents anyway you want.

A quick Google turns up a tool from Novell which may do what you want.
posted by nmiell at 12:13 AM on April 7, 2005


It's not pretty, but completely customizable if you know what you're doing. Here's a small script that will dump the common, first, and last name from the local domain.

The comments list the elements to change if you would a specific organizational unit, specific file name, or date format. The HTMLReport object takes the passed string elements for generating the report so you can add whatever visual customizations you want (CSS etc.). You can grab whatever user attributes you want by utilizing the object attributes (link only works in IE) available within Active Directory.

Highlight and copy the following and save it in a file with the extension ".wsf". Make sure you run it on a computer in the domain, and the user has adequate credentials to grab this information.

-- Start highlight below this link --
<package>
<job id="User-List">
<script language="vbscript">

Option Explicit
On Error Resume Next

' Declare public variables.
Dim FSO, adsRootDSE, strDomainPath, adsDefaultDomain, strDate, adsUsers, HTMLReport, intCounter

Const ForReading = 1, ForWriting = 2, ForAppending = 8, E_ADS_PROPERTY_NOT_FOUND = &h8000500D

Set FSO = CreateObject("Scripting.FileSystemObject")
Set adsRootDSE = GetObject("LDAP://RootDSE")
strDomainPath = adsRootDSE.Get("DefaultNamingContext")
Set adsDefaultDomain = GetObject("LDAP://" & strDomainPath)
Set adsRootDSE = Nothing

' ** Change these values to reflect your environment.
' This is the current date. Change it to meet whatever date format you would like to use.
strDate = Month(Date) & "-" & Day(Date) & "-" & Year(Date) ' Creates a date string delimited by hyphens.

' Location of user accounts. Default value: ("LDAP://" & strDomainPath) searches the entire domain.
Set adsUsers = GetObject("LDAP://" & strDomainPath)

' The file name for the report.
Set HTMLReport = FSO.OpenTextFile(strDate & ".User-List.html", ForWriting, true)

adsUsers.Filter = Array("organizationalUnit")

' Initialize counter.
intCounter = 0

' Generate HTML headers.
HTMLReport.WriteLine ( "<html><head>")
HTMLReport.WriteLine ( "<title>" & strDate & " - AD User List</title>")
HTMLReport.WriteLine ( "</head><body>")
HTMLReport.WriteLine ( "<h2>AD User List - Generated " & strDate & "</h2>")
HTMLReport.WriteLine ( "<table><tr><td>Common name</td><td>Given name</td><td>Surname</td></tr>")

Call EnumOUs(adsUsers)

' Close out the report.
HTMLReport.WriteLine ( "<h3>" & intCounter & " users.</h3></body></html>")
HTMLReport.Close

' Close out objects and quit the script.
Set HTMLReport = Nothing
Set adsUsers = Nothing
Set adsDefaultDomain = Nothing
Set FSO = Nothing
Wscript.Quit

Sub EnumOUs(objParent)

On Error Resume Next

Dim objUser, cn, givenName, surname, objChild

' Recursive subroutine to enumerate all OU's.
objParent.Filter = Array("User")
For Each objUser in objParent
If objUser.Class = "user" Then
' Expand on this if you would to grab other attributes.
cn = objUser.cn
givenName = objUser.givenName
surname = objUser.sn

' Generate unique row for user.
HTMLReport.WriteLine ( "<tr><td>" & cn & "</td><td>" & givenName & "</td><td>" & surname & "</td><tr>")
End If
Next

objParent.Filter = Array("organizationalUnit")

For Each objChild In objParent
Call EnumOUs(objChild)
Next
End Sub

</script>
</job>
</package>
-- End highlight above this line --

Hope that helps!
posted by purephase at 9:08 AM on April 7, 2005


« Older immediate intervention advice   |   Yeeaaarrrgghhhh Newer »
This thread is closed to new comments.