I think the problem lies somewhere else: if you get an object (e.g. a user) from the AD through its name and look at the ObjectGUID
, it contains a string like this:
(Get-QADUser -Identity myDomain\myUser).ObjectGUID
-> CAEC64A025153143A6755E0A3DAB5C1A
To get the same user through its GUID, you have to specify:
(Get-QADUser -Identity A064ECCA-1525-4331-A675-5E0A3DAB5C1A).ObjectGUID
-> CAEC64A025153143A6755E0A3DAB5C1A
If you compare the GUIDs you will notice that they look somewhat similar but not the same:
CAEC64A0-2515-3143-A675-5E0A3DAB5C1A
A064ECCA-1525-4331-A675-5E0A3DAB5C1A
This problem occurs because the System.GUID
uses a different byte-order than Active Directory to construct the GUID.
You can correct it like this (VB.NET):
Private Shared Function GetCorrectGuid(ByVal aWrongGuid As Guid) As Guid
Dim myGuidString As String = aWrongGuid.ToString("N")
Dim myWrongGuid As Char() = myGuidString.ToCharArray()
Dim myCorrectGuid As Char() = myGuidString.ToCharArray()
myCorrectGuid(0) = myWrongGuid(6)
myCorrectGuid(1) = myWrongGuid(7)
myCorrectGuid(2) = myWrongGuid(4)
myCorrectGuid(3) = myWrongGuid(5)
myCorrectGuid(4) = myWrongGuid(2)
myCorrectGuid(5) = myWrongGuid(3)
myCorrectGuid(6) = myWrongGuid(0)
myCorrectGuid(7) = myWrongGuid(1)
myCorrectGuid(8) = myWrongGuid(10)
myCorrectGuid(9) = myWrongGuid(11)
myCorrectGuid(10) = myWrongGuid(8)
myCorrectGuid(11) = myWrongGuid(9)
myCorrectGuid(12) = myWrongGuid(14)
myCorrectGuid(13) = myWrongGuid(15)
myCorrectGuid(14) = myWrongGuid(12)
myCorrectGuid(15) = myWrongGuid(13)
Return New Guid(New String(myCorrectGuid, 0, 32))
End Function
or this (C#):
private static Guid GetCorrectGuid(Guid aWrongGuid) {
string myGuidString = aWrongGuid.ToString("N");
char[] myWrongGuid = myGuidString.ToCharArray();
char[] myCorrectGuid = myGuidString.ToCharArray();
myCorrectGuid[0] = myWrongGuid[6];
myCorrectGuid[1] = myWrongGuid[7];
myCorrectGuid[2] = myWrongGuid[4];
myCorrectGuid[3] = myWrongGuid[5];
myCorrectGuid[4] = myWrongGuid[2];
myCorrectGuid[5] = myWrongGuid[3];
myCorrectGuid[6] = myWrongGuid[0];
myCorrectGuid[7] = myWrongGuid[1];
myCorrectGuid[8] = myWrongGuid[10];
myCorrectGuid[9] = myWrongGuid[11];
myCorrectGuid[10] = myWrongGuid[8];
myCorrectGuid[11] = myWrongGuid[9];
myCorrectGuid[12] = myWrongGuid[14];
myCorrectGuid[13] = myWrongGuid[15];
myCorrectGuid[14] = myWrongGuid[12];
myCorrectGuid[15] = myWrongGuid[13];
return new Guid(new string(myCorrectGuid, 0, 32));
}
And yes, I know this is not the most efficient way but I simply don't have the time to rewrite it now into a function that is based on a byte-array and that uses arraycopy. Sorry.
Hope that helps
chha