473,396 Members | 2,039 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Syntax question enumerating Active Directory Group Properties

I already tried posting this yesterday and it didn't post...

In a nutshell, I have a semi-functional app that does a few things
including searching the entire Active Directory for Groups and putting
the values of the CN, Description, and Info fields into a database.
The issue that I am experiencing is that when the foreach loop hits a
group with a null value in the description or info fields (the value
should be "") the app carry's the previous value over until it hits a
group that actually has a value. Then that value becomes "The Value"
that all the next value-less groups have displayed.

Perhaps some code will make this clearer:

<code>

using System;
using System.Data;
using System.DirectoryServices;
using System.Configuration;
using System.Collections;
using System.IO;
using System.Management;
using System.Data.SqlClient;
using System.DirectoryServices.ActiveDirectory;
using System.Text.RegularExpressions;
using System.Text;

namespace ADGroupEnum
{
class ADGroupEnum
{

static void Main(string[] args)
{
string strName = "";
string strInfo = "";
string strComment = "";
DirectoryEntry strLDAP = new
DirectoryEntry(@"LDAP://SERVER:389/OU=ROOT,DC=COMPANY,DC=com");
DirectorySearcher mySearcher = new
DirectorySearcher(strLDAP);
mySearcher.Filter = ("(objectClass=group)");
foreach (SearchResult resEnt in mySearcher.FindAll())
{
string strGroupName =
resEnt.GetDirectoryEntry().Name.ToString();
Match dl = Regex.Match(strGroupName, "(DL)");
Match USBOU1 = Regex.Match(strGroupName, "(USBOU1)");
/* All of our distribution lists begin with DL */
if (dl.Success)
{ }
else
{
/* All of our groups begin with USBOU1 */
if (USBOU1.Success)
{
foreach (string key in
resEnt.GetDirectoryEntry().Properties.PropertyName s)
{
/* I only want "cn", "description", and
"info" fields. I have verified that these fields all are valid and
have a VBSCRIPT that can properly collect this information */

foreach (object o in
resEnt.GetDirectoryEntry().Properties[key])
{
if (key == "cn")
{
if (o.ToString() == "")
{
strName = "";
}
else
{
strName = o.ToString();
}
}
else if (key == "description")
{
if (o.ToString() == "")
{
strComment = "";
}
else
{
strComment = o.ToString();
}
}
else if (key == "info")
{
if (o.ToString() == "")
{
strInfo = "";
}
else
{
strInfo = o.ToString();
}
}
}
}Writem(strName, strComment, strInfo);
}
}
}
}
public static void Writem(string name, string comment, string
info)
{
Console.WriteLine(name + "\n" + comment + "\n" + info +
"\n" + "============================================\ n");

}

}
}

</code>

What am I doing wrong here? I thought that the if (o.ToString() == "")
bit would get it to do what I wanted, but it doesn't seem to make any
difference.

Can anyone help?

Thanks!

Jan 10 '06 #1
1 2933
Oh, I guess it did post, I just couldn't find it under the main CSharp
group.

Jan 10 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Toufani | last post by:
Hi everybody, I want to retrieve information about objects in active directory windows 2000 and their properties. I got some codes that don't work absolutely. for example I can't retrieve users...
10
by: huzz | last post by:
I have web application that quaries the Active Directory to get user details.. everything works fine but someday I'll get System.Runtime.InteropServices.COMExection and if I restart the client...
2
by: Technical Group | last post by:
Friends, Can anybody help me out by sending a piece of C# code showing how to add an active directory user to a particular user group? If the group does not exist, then create it. Thanks in...
1
by: tangus via DotNetMonster.com | last post by:
Hello all, I'm really struggling with getting some Active Directory code to work in ASP.NET. Can you please provide assistance? I am executing the following code: Dim enTry As DirectoryEntry =...
0
by: AdamKadmon | last post by:
Hello Group, Below is (mostly)functional code that enumerates certain properties for all of the groups in my Active Directory. My question is contained within comments as well as here: Once I...
2
by: Daniel Knöpfel | last post by:
Hello all In our project we have been using the samAccount name to authenticate users against the active directory. As the samAccountName is limited to 20 characters, we are going to use the...
0
by: John | last post by:
Hello, i write this code (vs2005) for enumerating all users from a group.. But not it works.. if i set GroupSamAccountName = "Domain Users" i don't have any results.. Why?
2
by: Jim in Arizona | last post by:
My goal, somehow, is to populate a dropdownlist with all the user names in active directory. I don't even know where to begin, really. I added a reference to System.DirectoryServices so I could...
0
by: bcanter | last post by:
I found a file on the web that will allow you to enumerate groups but it was an .hta and the top level admins won't allow this. I need to give managers access to the groups so that when a new user is...
3
by: =?Utf-8?B?YXppZWdsZXI=?= | last post by:
Hello, everybody. I'd like to do this: For a big program (a web service) I need information about the usergroups an active-directory-user is member of. To be more precise, I need to know if a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
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,...
0
jinu1996
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
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,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.