Created
June 4, 2018 19:49
-
-
Save nmoinvaz/7e400ba5c10c930c27863d550765b6ba to your computer and use it in GitHub Desktop.
Powershell function to convert GUID string to static GUID
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() })) + | |
" } " + | |
"}" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Input: ConvertGuidStringToStaticGuid("{61FD2C0B-C8D4-48C1-A54F-BC5A64205AF4}")
Output: { 0x61FD2C0B, 0xC8D4, 0x48C1, { 0xA5, 0x4F, 0xBC, 0x5A, 0x64, 0x20, 0x5A, 0xF4 } }