Solved

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

Posted on 2004-10-13
4
189 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
Comment Utility
Hi

how is your AD setup?

do you have a specific users ou?

Scott
0
 
LVL 70

Accepted Solution

by:
Chris Dent earned 250 total points
Comment Utility

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
Comment Utility

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
Comment Utility
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

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

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 this article, I will show you HOW TO: Create your first Windows Virtual Machine on a VMware vSphere Hypervisor 6.5 (ESXi 6.5) Host Server, the Windows OS we will install is Windows Server 2016.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

743 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now