Solved

DSquery/DSget assistance

Posted on 2007-03-27
3
858 Views
Last Modified: 2012-06-21
I require a dsquery or dsget constructing so that I can obtain a list of users in a particular OU that are not members of 2 specific security groups.  The query should return the user ID and the first and last names.  Is anybody able to assist with this?
0
Comment
Question by:spjo1982
3 Comments
 
LVL 70

Accepted Solution

by:
Chris Dent earned 500 total points
ID: 18798909

You know... it might be possible to do that with DS Tools, but it's considerably easier to do in VbScript.

If that approach works for you then save the following as a .vbs file. You will have to fill in the Const values at the top. Run from the command line with "cscript scriptname.vbs" or it'll just pop up lots of boxes.


Const OU = "OU=SomeOU,OU=SomeWhere,DC=YourDomain,DC=com"
Const GROUP_1 = "The First Group Name"
Const GROUP_2 = "The Second Group Name"

Set objOU = GetObject("LDAP://" & OU)
objOU.Filter = Array("user")

For Each objUser in objOU
      strMemberOf = Join(objUser.GetEx("memberOf"))

      If InStr(1, strMemberOf, "CN=" & GROUP_1, VbTextCompare) = 0 And_
                  InStr(1, strMemberOf, "CN=" & GROUP_2, VbTextCompare) = 0 Then

            WScript.Echo objUser.Get("sAMAccountName") & VbTab & objUser.Get("givenName") &_
                  VbTab & objUser.Get("sN")
      End If
Next
0

Join & Write a Comment

The saying goes a bad carpenter blames his tools. In the Directory Services world a bad system administrator, well, even with the best tools they’re probably not going to become an all star.  However for the system admin who is willing to spend a li…
I'm sure that every Windows systems administrator has written, or at least used, a batch or VBS login script at some point in their career, whether it is to map network drives, install printers, or set some user preferences.  No more! With Window…
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…

747 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

10 Experts available now in Live!

Get 1:1 Help Now