I'm using the Active Directory Explorer from Mark Russinovich. It is a great tool.
I'm using it to navigate active directory to make sure my program that uses DirectorySearcher from .NET returns correct data.
Something happens though, when I try to search inside my program with DirectorySearcher for objectGUID, if I pass in the actual GUID as a string it doesn't return anything, where as if I use Active Directory Explorer, when I add
objectGuid with value f8d764ff-9a6a-418e-a641-b6f99661a8d5, its search clause becomes: (objectGUID=\FFd\D7\F8j\9A\8EA\A6A\B6\F9\96a\A8\D5*)
How do I do this for directorySearcher in my program, I'm guessign it's an octet string thing, but I can't figure it out.
The forums accompanying the excellent The .NET Developer's Guide to Directory Services Programming (Joe Kaplan / Ryan Dunn) is an excellent source for information like this.
Check out this thread here entitled Find the object using objectGuid property, which shows how you can convert a "regular" GUID to the S.DS "OctetString" format.
internal string ConvertGuidToOctetString(string objectGuid)
{
System.Guid guid = new Guid(objectGuid);
byte[] byteGuid = guid.ToByteArray();
string queryGuid = "";
foreach (byte b in byteGuid)
{
queryGuid += @"\" + b.ToString("x2");
}
return queryGuid;
}
This could be slightly optimized by using a StringBuilder instead of consecutively concatenating together a string - but it seems fairly straightforward otherwise.
Hope this helps.
Marc
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With