Capturing AD GUIDs to String
The results of a couple days of coding and Googling and such, I finally figured out how to output a GUID as it’s HEX format to a string.
1. Create a Property reader that outputs Objects rather than Strings.
public static object GetPropertyByte(SearchResult searchResult, string PropertyName)
2. Now, I have setup a switch statement to filter out the GUIDs, memberOf arrays, and regular strings. If you’re just capturing GUIDs, this is unnecessary. I’ve highlighted the key lines of GUID code in red.
System.Guid g = new System.Guid((System.Byte)GetPropertyByte(result1, sADUserColumn));
I had come across dozens of articles using ASCIIEncoding and other functions to manipulate the byte, but, finally managed to just try to force it into an actual GUID object and DING it worked!
: You could probably streamline this and have your GetProperty function JUST capture the Guid and return a Guid rather than an object. Heh, a later iteration though ’cause this works for now! LOL