Solved

insert code to prompt for OU to audit

Posted on 2015-01-23
4
93 Views
Last Modified: 2015-01-23
Hey experts.  Here is the code I am using to dump out the users in all the groups for a particular OU.

@echo off
cls

for /f "tokens=*" %%a in ('dsquery group "OU=x,DC=y" ^|sort') do (call :oumembers %%a)

exit /b

:oumembers
set ougroup=%1
echo %ougroup% >>ou-group-members.csv
::pause
for /f "tokens=*" %%b in ('dsget group %ougroup% -members ^|sort') do (call :usersamid %%b)
goto :eof

:usersamid
set userid=%1
for /f "tokens=*" %%c in ('dsquery user %userid% -o samid') do echo ,%%c >>ou-group-members.csv
goto :eof

Open in new window


I would like to have the script prompt for what OU to audit.  How can I do this?

Thanks Experts!
0
Comment
Question by:samiam41
  • 2
4 Comments
 
LVL 51

Accepted Solution

by:
Bill Prew earned 500 total points
ID: 40567165
Give this a try:

@echo off
cls

set OU=
set /p "OU=Please enter OU name: "
if "%OU%" EQU "" (
  echo No OU name entered, ending.
  exit /b
)

for /f "tokens=*" %%a in ('dsquery group "OU=%OU%,DC=y" ^|sort') do (call :oumembers %%a)

exit /b

:oumembers
set ougroup=%1
echo %ougroup% >>ou-group-members.csv
::pause
for /f "tokens=*" %%b in ('dsget group %ougroup% -members ^|sort') do (call :usersamid %%b)
goto :eof

:usersamid
set userid=%1
for /f "tokens=*" %%c in ('dsquery user %userid% -o samid') do echo ,%%c >>ou-group-members.csv
goto :eof

Open in new window

0
 
LVL 68

Expert Comment

by:Qlemo
ID: 40567166
To get a prompt, use
set /p ou=Please enter OU to dump 

Open in new window

This sets %ou% .
0
 
LVL 9

Author Closing Comment

by:samiam41
ID: 40567203
Clean and implemented it already.

Thank you for your help!

Qlemo, he got there first.  Hope you understand.
0
 
LVL 9

Author Comment

by:samiam41
ID: 40567215
A new question.  Thanks for your help if you have time.

http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/Q_28602795.html
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

If like me you are one who spends a lot of time working and scripting with cmd.exe, sometimes it is handy to be able to quickly view a calendar for a given month and year. This script will quickly do just that!  Save the code posted below to a .bat …
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
This Micro Tutorial will teach you how to the overview of Microsoft Security Essentials. This is a free anti-virus software that guards your PC against viruses, spyware, worms, and other malicious software. This will be demonstrated using Windows…
This Micro Tutorial will give you a basic overview of Windows Live Photo Gallery and show you various editing filters and touches to photos you can apply. This will be demonstrated using Windows Live Photo Gallery on Windows 7 operating system.

758 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

23 Experts available now in Live!

Get 1:1 Help Now