Solved

DSQUERY FOR USERS

Posted on 2009-07-13
6
445 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
[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
  • 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
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

Suggested Solutions

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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 …

733 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