I am trying to replace a node which has domainname\username.
As it has "\" it fails in regular expression match,
Invalid regular expression pattern: l8-dc\testuser2. At C:\Users\testuser1.l8-dc\Desktop\RunTimeAccountChange\UserAccount-Replace.ps1:164 char:68 + $Searchstr.Node.'#text'= $($Searchstr.Node.'#text') -replace <<<< $OldUserName,$NewUserN ame + CategoryInfo : InvalidOperation: (l4-dc\mesuser2:String) [], RuntimeException + FullyQualifiedErrorId : InvalidRegularExpression
The following line fails actually..
$Searchstr.Node.'#text'= $($Searchstr.Node.'#text') -replace $OldUserName,$NewUserName
How to replace with regular expression match?