Solved

insert code to prompt for OU to audit

Posted on 2015-01-23
4
101 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 54

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 69

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
While working, an annoying popup showing below will come and we cannot cancel or close it form the screen. The error message will come again and again.
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 DVD Burner through its features and interface. This will be demonstrated using Windows 7 operating system.

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