Skip to content

Instantly share code, notes, and snippets.

@milnak
Last active November 30, 2025 04:27
Show Gist options
  • Select an option

  • Save milnak/bef49acb9780a2a9ece4e4565b761c3c to your computer and use it in GitHub Desktop.

Select an option

Save milnak/bef49acb9780a2a9ece4e4565b761c3c to your computer and use it in GitHub Desktop.
PowerShell version of "GuidGen" application
param (
[ValidateSet('Ole', 'Define', 'Struct', 'Registry', 'AttributeBracket', 'AttributeBrace')]
[Parameter(Mandatory = $true, Position = 0)][string]$Type
)
function New-GuidObject {
$guid = (New-Guid).Guid
$m = Select-String `
-InputObject $guid `
-Pattern '([0-9A-Fa-f]{8})-([0-9A-Fa-f]{4})-([0-9A-Fa-f]{4})-([0-9A-Fa-f]{2})([0-9A-Fa-f]{2})-([0-9A-Fa-f]{2})([0-9A-Fa-f]{2})([0-9A-Fa-f]{2})([0-9A-Fa-f]{2})([0-9A-Fa-f]{2})([0-9A-Fa-f]{2})'
[PSCustomObject]@{
'Guid' = $guid.ToUpper()
'Data1' = $m.Matches.Groups[1].Value
'Data2' = $m.Matches.Groups[2].Value
'Data3' = $m.Matches.Groups[3].Value
'Data4_1' = $m.Matches.Groups[4].Value
'Data4_2' = $m.Matches.Groups[5].Value
'Data4_3' = $m.Matches.Groups[6].Value
'Data4_4' = $m.Matches.Groups[7].Value
'Data4_5' = $m.Matches.Groups[8].Value
'Data4_6' = $m.Matches.Groups[9].Value
'Data4_7' = $m.Matches.Groups[10].Value
'Data4_8' = $m.Matches.Groups[11].Value
}
}
switch ($Type) {
'Ole' {
$guid = New-GuidObject
"// {{{0}}}`nIMPLEMENT_OLECREATE(<<class>>, <<external_name>>,`n0x{1}, 0x{2}, 0x{3}, 0x{4}, 0x{5}, 0x{6}, 0x{7}, 0x{8}, 0x{9}, 0x{10}, 0x{11});" -f `
$guid.Guid, $guid.Data1, $guid.Data2, $guid.Data3, $guid.Data4_1, $guid.Data4_2, $guid.Data4_3, $guid.Data4_4, $guid.Data4_5, $guid.Data4_6, $guid.Data4_7, $guid.Data4_8
}
'Define' {
$guid = New-GuidObject
"// {{{0}}}`nDEFINE_GUID(<<name>>,`n0x{1}, 0x{2}, 0x{3}, 0x{4}, 0x{5}, 0x{6}, 0x{7}, 0x{8}, 0x{9}, 0x{10}, 0x{11});" -f `
$guid.Guid, $guid.Data1, $guid.Data2, $guid.Data3, $guid.Data4_1, $guid.Data4_2, $guid.Data4_3, $guid.Data4_4, $guid.Data4_5, $guid.Data4_6, $guid.Data4_7, $guid.Data4_8
}
'Struct' {
$guid = New-GuidObject
"/* {{{0}}} */`nstatic const GUID <<name>> =`n{{ 0x{1}, 0x{2}, 0x{3}, {{ 0x{4}, 0x{5}, 0x{6}, 0x{7}, 0x{8}, 0x{9}, 0x{10}, 0x{11} }} }};" -f `
$guid.Guid, $guid.Data1, $guid.Data2, $guid.Data3, $guid.Data4_1, $guid.Data4_2, $guid.Data4_3, $guid.Data4_4, $guid.Data4_5, $guid.Data4_6, $guid.Data4_7, $guid.Data4_8
}
'Registry' { '{{{0}}}' -f (New-GuidObject).Guid }
'AttributeBracket' { '[Guid("{0}")]' -f (New-GuidObject).Guid }
'AttributeBrace' { '<Guid("{0}")>' -f (New-GuidObject).Guid }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment