M
Martin
Hi,
Can anybody please tell me (or point me to documentation on) how to loop
through all AD properties of a user.
The code I have so far is below.
Now if I know the property name I can retrieve it, for eample to retrieve
"DisplayName"
I would just say.
de.Properties["DisplayName"].Value
so what I would like is just a display of all properties for a user,
something like this
DisplayName
Mail
Title
sAMAccountName
GivenName
it would also be nice to know what type a particular object is, for example
most properties are strings however I believe some properties are "C stucts"
cause they contain more than a single string although just to start I'd be
happy just to get the property names.
any help is appreciated
cheers
martin.
using System;
using System.DirectoryServices;
namespace TestConsole
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
string query;
//query =
ConfigurationSettings.AppSettings.Get("ActiveDirectoryQueryString");
query = "LDAP://mydomain";
System.DirectoryServices.DirectoryEntry entry = new
System.DirectoryServices.DirectoryEntry(query);
System.DirectoryServices.DirectorySearcher mySearcher = new
System.DirectoryServices.DirectorySearcher(entry);
try
{
foreach(System.DirectoryServices.SearchResult resEnt in
mySearcher.FindAll())
{
System.DirectoryServices.DirectoryEntry de=resEnt.GetDirectoryEntry();
//would like to get all properties (property name) here perhaps in a
foreach loop
foreach (DirectoryEntry child in de.Children)
{
Console.WriteLine(child.Name);
}
}
}
catch (Exception ex)
{
Console.WriteLine("ERROR ERROR ERROR " + ex.Message);
}
}
}
}
Can anybody please tell me (or point me to documentation on) how to loop
through all AD properties of a user.
The code I have so far is below.
Now if I know the property name I can retrieve it, for eample to retrieve
"DisplayName"
I would just say.
de.Properties["DisplayName"].Value
so what I would like is just a display of all properties for a user,
something like this
DisplayName
Title
sAMAccountName
GivenName
it would also be nice to know what type a particular object is, for example
most properties are strings however I believe some properties are "C stucts"
cause they contain more than a single string although just to start I'd be
happy just to get the property names.
any help is appreciated
cheers
martin.
using System;
using System.DirectoryServices;
namespace TestConsole
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
string query;
//query =
ConfigurationSettings.AppSettings.Get("ActiveDirectoryQueryString");
query = "LDAP://mydomain";
System.DirectoryServices.DirectoryEntry entry = new
System.DirectoryServices.DirectoryEntry(query);
System.DirectoryServices.DirectorySearcher mySearcher = new
System.DirectoryServices.DirectorySearcher(entry);
try
{
foreach(System.DirectoryServices.SearchResult resEnt in
mySearcher.FindAll())
{
System.DirectoryServices.DirectoryEntry de=resEnt.GetDirectoryEntry();
//would like to get all properties (property name) here perhaps in a
foreach loop
foreach (DirectoryEntry child in de.Children)
{
Console.WriteLine(child.Name);
}
}
}
catch (Exception ex)
{
Console.WriteLine("ERROR ERROR ERROR " + ex.Message);
}
}
}
}