Liest die verfügbaren Properties für eine Klasse aus.
using System.Collections.Generic;
using System.DirectoryServices.ActiveDirectory;
namespace AdExporter {
public class SchemaProperty {
public string Name { get; set; }
public string CommonName { get; set; }
public string Description { get; set; }
}
public class SchemaReader {
public static List<SchemaProperty> Read(string pDomainController, int pPortNumber,
string pUsername, string pPassword, string pClassName = "user") {
List<SchemaProperty> res = new List<SchemaProperty>();
DirectoryContext dirContext = new DirectoryContext(DirectoryContextType.DirectoryServer,
pDomainController + ":" + pPortNumber.ToString(), pUsername, pPassword);
ActiveDirectorySchema curSchema = ActiveDirectorySchema.GetSchema(dirContext);
ActiveDirectorySchemaClass userSchema = curSchema.FindClass(pClassName);
ReadOnlyActiveDirectorySchemaPropertyCollection props = userSchema.GetAllProperties();
foreach (ActiveDirectorySchemaProperty curProp in props) {
res.Add(new SchemaProperty() { Name = curProp.Name, CommonName = curProp.CommonName, Description = curProp.Description });
}
return res;
}
}
}
Kommentare zum Snippet