Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

insert code to prompt for OU to audit

Posted on 2015-01-23
4
Medium Priority
?
109 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
[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
  • 2
4 Comments
 
LVL 58

Accepted Solution

by:
Bill Prew earned 2000 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 71

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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
By default the complete memory dump option is disabled in windows . If we want to enable the complete memory dump for a diagnostic purpose, we have a solution for it. here we are using the registry method to enable this.
This Micro Tutorial will give you basic overview of the control panel section on Windows 7. It will depth in Network and Internet, Hardware and Sound, etc. This will be demonstrated using Windows 7 operating system.
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.

610 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