We help IT Professionals succeed at work.

Get all groups from a particular OU

422 Views
Last Modified: 2010-03-05
Hi,

I have some Groups on my root domain so need a way where i can specify the OU path so that i can get all groups from that OU.

REgards
Sharath
Comment
Watch Question

CERTIFIED EXPERT
Most Valuable Expert 2019
Most Valuable Expert 2018

Commented:
Use dsquery:
dsquery group "ou=SomeOU,ou=SomeOtherOU,dc=your,dc=domain,dc=local"
Among othger things, you can as well specify the output format using -o, and you can specify the scope to search using -scope.
Check "dsquery -?" or http://technet2.microsoft.com/windowsserver/en/library/46ba1426-43fd-4985-b429-cd53d3046f011033.mspx?mfr=true for details
Farhan KaziSystems Engineer
CERTIFIED EXPERT
Top Expert 2007

Commented:
* Following batch script will get all the members of groups that are specified in Groups.txt file.
* It will generate a file on C: drive root with name GroupMembers.txt having all members information.
* Copy and paste following script in notepad and save it with .BAT extension.

:: *** BATCH SCRIPT START ***
@Echo Off
SETLOCAL
IF NOT EXIST C:\groups.txt Goto ShowErr
FOR %%R IN (C:\groups.txt) Do IF %%~zR EQU 0 Goto ShowErr
IF EXIST C:\GroupMembers.txt DEL /F /Q C:\GroupMembers.txt

FOR /F "delims=#" %%g in (C:\groups.txt) Do (
      Echo Retrieving members of group: %%g
      Echo Retrieving members of group: %%g               >>C:\GroupMembers.txt
      DSQuery group -name "%%g*" | dsget group -members >>C:\GroupMembers.txt
      Echo. >>C:\GroupMembers.txt
)

Goto EndScript
:ShowErr
Echo C:\groups.txt file does not exist or file is empty!
:EndScript
ENDLOCAL
:: *** BATCH SCRIPT END ***

Hope it helps.
Farhan KaziSystems Engineer
CERTIFIED EXPERT
Top Expert 2007

Commented:
Ohoh! Sorry I answered to the wrong question.

Author

Commented:
Any help....
CERTIFIED EXPERT
Most Valuable Expert 2019
Most Valuable Expert 2018

Commented:
The dsquery command above will "get all groups from that OU".
You need to be more specific if you requiore more help.

Author

Commented:
Hi OBDA,

I have a primary and a secondary domain.

EX: Root is "All" and below it is "development".

When ever i run any query it fetches all the details from the development domain not the All domain.That's the reason i wanted a way to be specific .where we can mention the OU and DC.

REgards
Sharath
CERTIFIED EXPERT
Most Valuable Expert 2019
Most Valuable Expert 2018

Commented:
As in the example above; dsquery expects the node to start its search as argument:
dsquery group "dc=development,dc=all,dc=local"
or whatever.
You can specify the server or domain to query as well using the -s or -d switch; check the link above for details.
Systems Engineer
CERTIFIED EXPERT
Top Expert 2007
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.