title: Replace string of text in powershell
body: <p>I'm trying to replace string of text and I get  <code>The regular expression pattern  is not valid.</code></p>
  <p>This is to be able to change a policy using LGPO</p>
  <pre><code>$TextToBeReplaced=&quot;Computer`r`nSOFTWARE\Policies\Microsoft\Windows\DeviceGuard`r`nDeployConfigCIPolicy`r`nDWORD:1`r`n`r`nComputer`r`nSOFTWARE\Policies\Microsoft\Windows\DeviceGuard`r`nConfigCIPolicyFilePath`r`nSZ:C:\\WL\\politicas\\DeviceGuardPolicy.bin&quot;
  
  $NewText=&quot;Computer`r`nSOFTWARE\Policies\Microsoft\Windows\DeviceGuard`r`nDeployConfigCIPolicy`r`nDELETE`r`n`r`nComputer`r`nSOFTWARE\Policies\Microsoft\Windows\DeviceGuard`r`nConfigCIPolicyFilePath`r`nDELETE&quot;
  
  ((Get-Content -path $LGPOTxt -Raw) -replace $TextToBeReplaced,$NewText) | Set-Content -Path $LGPOTxt
  </code></pre>
  <p>LGPO.txt contains this what I have to change is this string for the other in order to apply the new LGPO policy</p>
  <pre><code>; ----------------------------------------------------------------------
  ; PARSING Computer POLICY
  ; Source file:  C:\WL\LGPO\LGPOBackUp\DomainSysvol\GPO\Machine\registry.pol
  
  Computer
  SOFTWARE\Policies\Microsoft\Windows\DeviceGuard
  DeployConfigCIPolicy
  DWORD:1
  
  Computer
  SOFTWARE\Policies\Microsoft\Windows\DeviceGuard
  ConfigCIPolicyFilePath
  SZ:C:\\WL\\politicas\\DeviceGuardPolicy.bin
  
  ; PARSING COMPLETED.
  ; ----------------------------------------------------------------------
  </code></pre>
  <p>Any way to do this?</p>