Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Retreive users and properties from Active Directory (Moderately Urgent...)

Posted on 2005-04-04
2
Medium Priority
?
255 Views
Last Modified: 2010-04-17
Hi!

I need to take users from certain OUs and their properties to either an XML document or a SQL database.
In the past I've used a VB6 exe ran from a SQL job but I'd like to know what would be the best way to do this.
Either an exe in VB.Net or a vbscript, WS or something like that.
 
What I need is all the users in certain OUs and their names, email, address, title etc.

Thanks!
-JTM
0
Comment
Question by:Jonthemoon
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 15

Assisted Solution

by:sr75
sr75 earned 600 total points
ID: 13697524
Here is a script that you could modify for your needs:

On Error Resume Next

Dim objConnection, objCommand, objRecordSet, objNewOU, objMoveComputer
Dim strComputer, strInitial, strSourceOU, strDestinationOU
Dim intCounter

Const ADS_SCOPE_SUBTREE = 2
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"

Set objCOmmand.ActiveConnection = objConnection

objCommand.CommandText ="Select Name, Location from 'LDAP://ou=accounting,dc=rave,dc=ravellc,dc=com'" _
       & "where objectClass='user'"
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Timeout") = 30
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.Properties("Cache Results") = False

Set objRecordSet = objCommand.Execute

Set FSO = CreateObject("Scripting.FileSystemObject")

Do Until objRecordSet.EOF

      strUser = objRecordSet.Fields("Name").Value

        Set Logfile = FSO.OpenTextFile("User.txt", 8 ,true)
      Logfile.writeline strUser
      Logfile.close

      objRecordSet.MoveNext
Loop
0
 
LVL 2

Accepted Solution

by:
vinil earned 732 total points
ID: 13697607
Are you looking for a code snippet that will enumerate all the users in the AD fitting your criteria, or are you looking for pros/cons of the various approaches?

The ADSI objects can be accessed just as easily in a script as in VB and I do not see why .NET should be any different in case you want to consume it via a WS or a VB.NET app.

These sites might be useful:
0. http://www.petri.co.il/list_all_users_and_groups_in_domain.htm *Highly recommended*
1. http://www.windowsitpro.com/WindowsScripting/Article/ArticleID/4734/4734.html

These sites were found to contain additional information
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ad/ad/enumerating_users.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnclinic/html/scripting04132004.asp
http://msdn.microsoft.com/library/en-us/adsi/adsi/creating_new_users_in_the_organizational_unit.asp
http://msdn.microsoft.com/library/en-us/adsi/adsi/enumerating_objects.asp

HTH,
Vinil
P.S. Since am not on an AD, cannot provide with you a running script :(
0

Featured Post

Office 365 Training for IT Pros

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Office 365 is a subscriptions based service which includes services like Exchange Online and Skype for business Online. These services integrate with Microsoft's online version of Active Directory called Azure Active Directory.
A bad practice commonly found during an account life cycle is to set its password to an initial, insecure password. The Password Reset Tool was developed to make the password reset process easier and more secure.
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Suggested Courses

704 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question