C# Convert Active Directory Hexadecimal to GUID C# Convert Active Directory Hexadecimal to GUID powershell powershell

C# Convert Active Directory Hexadecimal to GUID


Guid has a constructor which takes a byte array

You can convert the hexadecimal string into a byte array and use that to construct a new Guid.

If you need to know how to convert the hexadecimal string to a byte array, Stack Overflow already has a few answers to that question.

From the accepted answer of that question:

public static byte[] StringToByteArray(String hex){  int NumberChars = hex.Length;  byte[] bytes = new byte[NumberChars / 2];  for (int i = 0; i < NumberChars; i += 2)    bytes[i / 2] = Convert.ToByte(hex.Substring(i, 2), 16);  return bytes;}