Created
December 12, 2022 10:19
-
-
Save djonasdev/c38c4585ec338740e0da8bec319b72c9 to your computer and use it in GitHub Desktop.
Easily replace all GUID in a WIX-Toolset-Installer file | It is also usable on any other file
This file contains hidden or 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
## GuidSwap.ps1 | |
## | |
## Reads a file, finds any GUIDs in the file, and swaps them for a NewGUID | |
## | |
$filename = "HMI.wxs" | |
$outputFilename = "HMI_newGuids.wxs" | |
$text = [string]::join([environment]::newline, (get-content -path $filename)) | |
$sbNew = new-object system.text.stringBuilder | |
$pattern = "[a-fA-F0-9]{8}-([a-fA-F0-9]{4}-){3}[a-fA-F0-9]{12}" | |
$lastStart = 0 | |
$null = ([regex]::matches($text, $pattern) | %{ | |
$sbNew.Append($text.Substring($lastStart, $_.Index - $lastStart)) | |
$guid = [system.guid]::newguid().ToString().ToUpper() | |
$sbNew.Append($guid) | |
$lastStart = $_.Index + $_.Length | |
}) | |
$null = $sbNew.Append($text.Substring($lastStart)) | |
$sbNew.ToString() | out-file -encoding ASCII $outputFilename | |
Write-Output "Done" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment