How to access the comments field of a GroupPrincipal object

I am querying all security groups in a specific domain using

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

      

where ps is PrincipalSearcher.

Then I need to iterate through the result (by first dragging it into a GroupPrincipal) and find the ones that contain a specific string in the comments field.

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

Update: I gave up on this. There seems to be no way to access this annoying Notes field.

+1


source to share


4 answers


I come back to this challenge again and again, but now I finally gave up. He is confident that this property is not available.



+1


source


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 actually called info in the AD schema)
string NotesPropertyContent = UnderlyingDirectoryObject.Properties["info"].Value;

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

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

      



Took a bit of hunting - I assumed the notes property was indeed called "notes", ADSIEdit for help!

+6


source


For anyone using the "info" attribute: note that it will throw an exception if an empty string or null is used.

+1


source


i managed to change this field.

...

entryToUpdate.Properties ["Information"] Clear (); entryToUpdate.Properties ["info"]. Add ("some text you want here");

So thanks to Brad :)

+1


source







All Articles