Solved

insert code to prompt for OU to audit

Posted on 2015-01-23
4
98 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 53

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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

When you start your Windows 10 PC and got an "Operating system not found" error or just saw  "Auto repair for startup" or a blinking cursor with black screen. A loop for Auto repair will start but fix nothing.  You will be panic as there are no back…
When you try to share a printer , you may receive one of the following error messages. Error message when you use the Add Printer Wizard to share a printer: Windows could not share your printer. Operation could not be completed (Error 0x000006…
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.
The Task Scheduler is a powerful tool that is built into Windows. It allows you to schedule tasks (actions) on a recurring basis, such as hourly, daily, weekly, monthly, at log on, at startup, on idle, etc. This video Micro Tutorial is a brief intro…

831 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