Solved

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

Posted on 2004-10-13
4
197 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 70

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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Adprep 12 85
Can you expand C: in Windows 2000? 5 137
Windows 2000 server can't ping domain controller until after clearing arp cache 6 69
Windows  Active Directory  Quesiton 8 131
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…
Smart phones, smart watches, Bluetooth-connected devices—the IoT is all around us. In this article, we take a look at the security implications of our highly connected world.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

820 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