Solved

DSQUERY FOR USERS

Posted on 2009-07-13
6
442 Views
Last Modified: 2013-11-10
I need a script that does the following:

-Generate a list of all users my domain and save to a text file
-It must NOT list the user account that have been disabled

I am not too concerned with how pretty the output file looks as I will use Excel to import it into a workbook.  So the following format is ok:
"CN=Charles Ross,CN=Users,DC=mogan,DC=local"

Open in new window

0
Comment
Question by:every1isevil2
  • 5
6 Comments
 
LVL 20

Expert Comment

by:MightySW
ID: 24844035
Hi, you will need an AD export script.

Try this site:

http://www.visualbasicscript.com/m_29830/tm.htm

Copy the text and then save it as a .vbs file

They have a great example that will go to excel.

HTH
0
 
LVL 20

Expert Comment

by:MightySW
ID: 24844070
Wow, I just tried this.  It is AWESOME!  It will do everything you ask and more.  You can edit the fields as necessary.
0
 
LVL 20

Expert Comment

by:MightySW
ID: 24844105
Ok, I see you have the disabled disclaimer in there.  Let me see what I can do.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 4

Author Comment

by:every1isevil2
ID: 24844118
Thank you for the fast reply.

After looking at the code, which is quite nice, I am afraid that it does not meet either of my requirements.  I need it to send it to: a) text file and b) leave out disabled user accounts.

Please submit syntax/code.
0
 
LVL 20

Accepted Solution

by:
MightySW earned 500 total points
ID: 24845062
Ok, here you go.

Just wrote it out and tested.

Works great.  You may want to remove the disabled = no column.  

What happens is the query looks for disable accounts being set to 'yes' and filters them with dsget.

HTH



@echo off & Setlocal EnableDelayedExpansion

title Users that have not changed their password for at least 80 days.
 

:: note, Useraccounts that are Disabled 

:: are filtered out and these users do not appear on the list. 
 

:: There is also a disabled column.  You can remove that as necessary
 

:: Set the strOU to your applicable domain name and root  (domain.com) would be DC=domain,DC=com  (no spaces)
 

:: Will send txt file to C:\getusers.txt.  
 

:: There is not a limit on this query.
 

Set "strOU=DC=FQDN_DOMAIN_NAME_Suffix,DC=com"
 

echo/QUERYING (incl. sub-OUs):

echo/%strOU%

echo/
 

Set /a iCnt=0

For /f "skip=1 delims=" %%a in ( 

	'dsquery.exe user "%strOU%" -name * -limit 0 -stalepwd 0 ^| dsget user -disabled -dn ^|Findstr /iv "\<yes\>" ^|Findstr /iv "\<dsget\>" ^> c:\getUsers.txt'

	) DO (

   	echo %%a 

    	)
 

echo/&echo/&echo/finished.&pause>nul

Open in new window

0
 
LVL 20

Expert Comment

by:MightySW
ID: 24845067
Its actually set for stalepassword of 0, so it will get everybody.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
A quick step-by-step overview of installing and configuring Carbonite Server Backup.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

762 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

18 Experts available now in Live!

Get 1:1 Help Now