473,389 Members | 1,346 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,389 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 2931
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
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
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
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?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
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...

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.