views:

204

answers:

2

I query all security groups in a specific domain using

PrincipalSearchResult<Principal> results = ps.FindAll();

where ps is a PrincipalSearcher.

I then need to iterate the result (casting it to a GroupPrincipal first ) and locate the ones that contains a specific string in the notes field.

But the Notes field from AD is appearently not a public field in the GroupPrincipal class, doh. What am I doing wrong ?

Update: I have given up on this one. It seems like there is no way to access that pesky Notes field.

A: 

I have been returning to this challange over and over again, but now I have finally given up. It sure looks like that property is inaccessible.

Kasper
+1  A: 

You can access the 'notes' field of a directory entry as such:

// Get the underlying directory entry from the principal
System.DirectoryServices.DirectoryEntry UnderlyingDirectoryObject =
     PrincipalInstance.GetUnderlyingObject() as System.DirectoryServices.DirectoryEntry;

// Read the content of the 'notes' property (It's actually called info in the AD schema)
string NotesPropertyContent = UnderlyingDirectoryObject.Properties["info"].Value;

// Set the content of the 'notes' field (It's actually called info in the AD schema)
UnderlyingDirectoryObject.Properties["info"].Value = "Some Text"

// Commit changes to the directory entry
UserDirectoryEntry.CommitChanges();

Took a little bit of hunting - I had assumed the notes property was indeed called 'notes', ADSIEdit to the rescue!

Brad