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
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 to share