There are two ways of replacing text in a string: the Replace() method, and the –replace operator. They work fundamentally different.
Replace() is case-sensitive and replaces text with new text:
PS> 'Hello World.'.Replace('o', '0')
PS> 'Hello World.'.Replace('ell','oo')
The -replace operator is by default case-insensitive (use -creplace if you want case sensitivity). It accepts a regular expression, and that is what most people miss:
PS> 'Hello World.' -replace 'ell', 'oo'
PS> 'Hello World.' -replace '.', '!'
The second outcome surprises those that don’t know about regular expressions. If you want -replace to replace static text, make sure you escape your text:
PS> 'Hello World.' -replace [Regex]::Escape('.'), '!'
ReTweet this Tip!
PS> 'Hello World.' -replace '\.', '!'
Powered by IDERA