Replacing GUIDS in a file using PowerShell

A quick line of PowerShell code that replaces existing GUIDS in a file with completely new randomly generated GUIDS (Should all be on one line):

(get-content .\Input.xml) | 
ForEach-Object {$_ -replace "\{[0-9a-z\-]*\}",
("{" + [guid]::newguid()  + "}")} |
 Set-Content output.xml -Encoding UTF8

The code basically does a find and replace using a regular expression, then outputs the new content to the output.xml file. The encoding output is completely up to you, mine is set to UTF-8 as it matched the input file.

Richard

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s