Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to query the Active Directory and return all user logon names?

Posted on 2004-10-13
4
Medium Priority
?
210 Views
Last Modified: 2010-04-14
Hi,

We are running Win2K server with Active Directory. I need to run a report from the AD, specifically, querying the AD for user logon names, and returning a report which is a list of all user logon names.

I have no idea how I would do this - can anyone help?

thanks!
0
Comment
Question by:gjirvine3000
  • 2
4 Comments
 
LVL 15

Expert Comment

by:Colosseo
ID: 12296744
Hi

how is your AD setup?

do you have a specific users ou?

Scott
0
 
LVL 71

Accepted Solution

by:
Chris Dent earned 750 total points
ID: 12296756

In AD Users and Computers...

Add the "Pre-Windows 2000 Logon Name" Column, and / or the User Logon Name (depending on which you favour).

Select "Export List..." from the Right Click menu, then open the resulting file in Excel.

Does that work well enough for you?
0
 

Author Comment

by:gjirvine3000
ID: 12296762

I think it is set up in the default way.

I have the main container - companyname.co.uk.

Underneath that there is:

Builtin
Computers
Domain Controllers
ForeignSecurityPrincipals
LostAndFound
Microsoft ExchangeSystemObjects
System
Users

Thanks
0
 
LVL 15

Expert Comment

by:Colosseo
ID: 12296813
Hi

Ok the only problem with this code might be the strADSPath = line as it might be incorrect for your AD.

The code however does work fine :)

What you need to do is create a file called (for example getLogonNames.vbs) then cut and paste the code below into the file, save it then double click it to run.

A file called output.txt will be created in the c:\ folder (you can change this to whatever you want of course) and the logon names will be written to it.

A message box is displayed so that you know when the code has finished (again you can remove this if you dont want it)

code below:

  ' This code returns the user names of all the users in the specified ou

  ' Create a reference to the filesystem object
  Set objFSO = CreateObject("Scripting.FileSystemObject")

  ' Create the output file
  Set objOutput = objFSO.CreateTextFile("c:\output.txt")

  strADSPath = "LDAP://CN=Users,DC=companyname,DC=co,DC=uk" 'The OU containing the users

  ' Connect to the OU
  Set objOU = getObject(strADsPath )

  ' For each object in the OU
  For each objUser in objOU
    ' If the object is a user
    If objUser.class = "user" Then
      ' Add the users logon name to the text file
      objOutput.WriteLine objUser.sAMAccountName
    End If
  Next

  ' Close the output file
  objOutput.Close

  ' Clear the references
  Set objOU = Nothing
  Set objOutput = Nothing
  Set objFSO = Nothing

  ' Alert the user when the search is complete
  Msgbox "Search Complete!"

Cheers, any problems let me know

Scott
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

NTFS file system has been developed by Microsoft that is widely used by Windows NT operating system and its advanced versions. It is the mostly used over FAT file system as it provides superior features like reliability, security, storage, efficienc…
In a use case, a user needs to close an opened report by simply pressing the Escape (Esc) key. This can be done by adding macro code in Report_KeyPress or Report_KeyDown event.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Loops Section Overview
Suggested Courses

971 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