?
Solved

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

Posted on 2004-10-13
4
Medium Priority
?
205 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 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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

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…
When trying to connect from SSMS v17.x to a SQL Server Integration Services 2016 instance or previous version, you get the error “Connecting to the Integration Services service on the computer failed with the following error: 'The specified service …
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…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses

719 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