Solved

DSquery/DSget assistance

Posted on 2007-03-27
3
859 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

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

In this article, I am going to show you how to simulate a multi-site Lab environment on a single Hyper-V host. I use this method successfully in my own lab to simulate three fully routed global AD Sites on a Windows 10 Hyper-V host.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

867 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

15 Experts available now in Live!

Get 1:1 Help Now