Richie Lee has a Powershell snippet to replace text:
Below is a function that will search in a string and replace a character in a variable. Simple enough. It generally saves time in calling this from a helper file in source control for tidying up variables that are passed in to a Powershell function that aren’t quite formatted as required. A good example of this is upstream build variables with spaces in TeamCity.
Click through for the script.