Skip to content

Instantly share code, notes, and snippets.

@nmoinvaz
Created June 4, 2018 19:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nmoinvaz/7e400ba5c10c930c27863d550765b6ba to your computer and use it in GitHub Desktop.
Save nmoinvaz/7e400ba5c10c930c27863d550765b6ba to your computer and use it in GitHub Desktop.
Powershell function to convert GUID string to static GUID
function ConvertGuidStringToStaticGuid($GuidString)
{
$g = [Guid]$GuidString
"{ " +
(@([BitConverter]::ToInt32(($g.ToByteArray() | Select -First 4),0),
[BitConverter]::ToInt16(($g.ToByteArray() | Select -Index (4..5)),0),
[BitConverter]::ToInt16(($g.ToByteArray() | Select -Index (6..7)),0)
) | ForEach-Object { "0x" + $_.ToString("x2").ToUpper() + "," }) +
" { 0x" +
[System.String]::Join(", 0x",
(($g.ToByteArray() | Select -Index (8..15)) | ForEach-Object { $_.ToString("x2").ToUpper() })) +
" } " +
"}"
}
@nmoinvaz
Copy link
Author

nmoinvaz commented Jun 4, 2018

Input: ConvertGuidStringToStaticGuid("{61FD2C0B-C8D4-48C1-A54F-BC5A64205AF4}")
Output: { 0x61FD2C0B, 0xC8D4, 0x48C1, { 0xA5, 0x4F, 0xBC, 0x5A, 0x64, 0x20, 0x5A, 0xF4 } }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment