System.DirectoryService namespace provides many useful utilitu to communicate with AD, especially when you are querying object information. However, when querying AD object by objectSID, there’s a trick.
To query AD via System.DirectoryService namespace, first we have to create searcher object.
Then to set query filter, in this case , I am searching objects by its sid.
And to get correct SID string for query.
We can not simply put filter like objectSid=S-1-5, to get this query work, we have to convert SID into format like \00\01\05…