Created
December 29, 2025 18:05
-
-
Save Daggerpov/803bbee2cb7dce48cbe4846a6ce143c1 to your computer and use it in GitHub Desktop.
Replace all Guids in a 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 | |
| ## | |
| # Paste whichever file you'd like to execute this script for | |
| # IMPORTANT. | |
| $filename = "{FILEPATH HERE}" | |
| $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() | |
| $sbNew.Append($guid) | |
| $lastStart = $_.Index + $_.Length | |
| }) | |
| $null = $sbNew.Append($text.Substring($lastStart)) | |
| $sbNew.ToString() | out-file -encoding ASCII $filename | |
| Write-Output "Done" |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Inspiration: https://stackoverflow.com/questions/2201740/replacing-all-guids-in-a-file-with-new-guids-from-the-command-line/2283754#2283754
Powershell command on Windows to run:
powershell -noexit C:\Users\{filepath of the above script}.ps1