I want to get a list of users from a specific AD group. I use this
code:
************************************************** **************************************
SearchResult result;
DirectorySearcher search = new DirectorySearcher();
search.Filter = String.Format("(cn={0})", groupName);
search.PropertiesToLoad.Add("member");
result = search.FindOne();
ArrayList userNames = new ArrayList();
if (result != null)
{
for (int counter = 0; counter <
result.Properties["member"].Count; counter++)
{
string user = (string)result.Properties["member"][counter];
userNames.Add(user);
}
}
************************************************** **************************************
When the code is finished user string = "CN=Egholm Jacob (DFDS
A/S),OU=Development,OU=IT,OU=DFDS AS,DC=dk,DC=dfds,DC=root"
But what I want to do is getting information like givenName,
displayName etc. from the user.
What shall I do? 5 9609
You should load the givenName and displayName property from the AD.
string[] props = {"givenName ", "displayName", ".."};
search.PropertiesToLoad.AddRange(props);
....
Willy.
<eg****@gmail.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com... I want to get a list of users from a specific AD group. I use this code:
************************************************** ************************************** SearchResult result; DirectorySearcher search = new DirectorySearcher(); search.Filter = String.Format("(cn={0})", groupName); search.PropertiesToLoad.Add("member"); result = search.FindOne();
ArrayList userNames = new ArrayList(); if (result != null) { for (int counter = 0; counter < result.Properties["member"].Count; counter++) { string user = (string)result.Properties["member"][counter]; userNames.Add(user); } }
************************************************** **************************************
When the code is finished user string = "CN=Egholm Jacob (DFDS A/S),OU=Development,OU=IT,OU=DFDS AS,DC=dk,DC=dfds,DC=root"
But what I want to do is getting information like givenName, displayName etc. from the user. What shall I do?
Thanks for your reply. I have change my code to this:
************************************************** ***************************************
SearchResult result;
DirectorySearcher search = new DirectorySearcher();
search.Filter = String.Format("(cn={0})", groupName);
search.PropertiesToLoad.Add("member");
search.PropertiesToLoad.Add("displayName");
result = search.FindOne();
ArrayList userNames = new ArrayList();
if (result != null)
{
for (int counter = 0; counter <
result.Properties["member"].Count; counter++)
{
string user = (string)result.Properties["member"][counter];
string test =
(string)result.Properties["displayName"][counter];
userNames.Add(user);
}
}
************************************************** ***************************************
The string variable test returns the name of the group and not the name
of the user in the group.
<eg****@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
Thanks for your reply. I have change my code to this:
************************************************** ***************************************
SearchResult result;
DirectorySearcher search = new DirectorySearcher();
search.Filter = String.Format("(cn={0})", groupName);
search.PropertiesToLoad.Add("member");
search.PropertiesToLoad.Add("displayName");
result = search.FindOne();
ArrayList userNames = new ArrayList();
if (result != null)
{
for (int counter = 0; counter <
result.Properties["member"].Count; counter++)
{
string user = (string)result.Properties["member"][counter];
string test =
(string)result.Properties["displayName"][counter];
userNames.Add(user);
}
}
************************************************** ***************************************
The string variable test returns the name of the group and not the name
of the user in the group.
If your cn denotes a "username", you should apply the following filter.
src.Filter = "(objectCategory=user)";
also, you should not use a for loop to iterate, use foreach instead.
Willy.
Hello Willy
I have change my code (look below), but it still dosen't work.
************************************************** ***************************************
DirectoryEntry searchRoot = new DirectoryEntry(@"LDAP://dfds.root");
DirectorySearcher search = new DirectorySearcher(searchRoot);
search.Filter = "(&(cn=Group CFS Handlers)(objectCategory=user))";
search.PropertiesToLoad.Add("samaccountname");
foreach (SearchResult res in search.FindAll())
{
string dummy = res.Properties["samaccountname"].ToString();
}
************************************************** ***************************************
I want to list all the users in the group "Group CFS Handlers", but
search.FindAll() returns 0 results. I just checked the AD and the group
"Group CFS Handlers" contain one user.
I you have any idea what I do wrong, please let my know. I believe it
has something to do with my filter, but I don't know what.
Hello Willy
I have change my code (look below), but it still dosen't work.
************************************************** ***************************************
DirectoryEntry searchRoot = new DirectoryEntry(@"LDAP://dfds.root");
DirectorySearcher search = new DirectorySearcher(searchRoot);
search.Filter = "(&(cn=Group CFS Handlers)(objectCategory=user))";
search.PropertiesToLoad.Add("samaccountname");
foreach (SearchResult res in search.FindAll())
{
string dummy = res.Properties["samaccountname"].ToString();
}
************************************************** ***************************************
I want to list all the users in the group "Group CFS Handlers", but
search.FindAll() returns 0 results. I just checked the AD and the group
"Group CFS Handlers" contain one user.
I you have any idea what I do wrong, please let my know. I believe it
has something to do with my filter, but I don't know what. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: scott289 |
last post by:
Getting the lists of users in a given Domain Group?
For example, our Network people have created a group called MyAppUsers,
and have added certain Users to this group. I need to get a list of...
|
by: BobTheDatabaseBoy |
last post by:
.... got: win2K, v8.1.6
login to win2K is to the network: user; bob13, domain; foo
it's a win2K domain.
i then login to my local db as db2admin. LIST APPLICATIONS
fails with security error. ...
|
by: Mike Turco |
last post by:
(This was also posted to comp.database.ms-access before I realized this was
the hep group.)
Lets say that my WinXP computer has two users: Michael and Kathryn. One or
the other logs into the...
|
by: Rod |
last post by:
I have been working with ASP.NET 1.1 for quite a while now. For some
reason, opening some ASP.NET applications we wrote is producing the
following error message:
"The Web server reported...
|
by: Derek Martin |
last post by:
Using VB.Net, I would like to retrieve the currently logged in user's DN
from Active Directory. Alternatively, if, using WindowsIdentity, or
something similar, I would like to get the user's full...
|
by: wqyuwss |
last post by:
Hi,
We have several core dumps in our product. These core dump can be
reproduced in the same place. That is system function call
std::basic_istream<char,std::char_traits<char>>::getline. The...
|
by: Mike Spike |
last post by:
HI all,
How do I go about getting the permmisions of a file.
I have been able to get a list of access control rules and tell if they are
restricting or permiting a permmision but I cant tell...
|
by: shashank kadge |
last post by:
hi all,
i am trying to get local admin users and groups on a windows server.
here is the C# code that i am using...
|
by: Michael Howes |
last post by:
I'm writing a utility to manage a machines *local* accounts in c#
I am getting all the users in a specific Group just fine but when I
want to get some of the information on each user from their...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |