Solved

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

Posted on 2004-10-13
4
199 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
[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
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 250 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
First of all let me say that the only language that I speak is English, but in answering questions here I often come across people whose English skills are not the best and I’d like to be able to communicate better with them, and the following descr…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

622 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