Solved

DSQUERY FOR USERS

Posted on 2009-07-13
6
443 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
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
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

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

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

Suggested Solutions

A quick step-by-step overview of installing and configuring Carbonite Server Backup.
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
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 …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

947 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

20 Experts available now in Live!

Get 1:1 Help Now