'Modify lines in a .CSS file using PowerShell

I want to modify some lines in a .CSS file using PowerShell

I tried the following commands, but the resulting file duplicates parts of the CSS

 $data = foreach($line in Get-Content .\folder\bundle.css) {

  if($line -like "*.header-container{*") {
    $line -replace ".header-container{", ".header-container{display:none !important;"
  }

  if($line -like "*.header2_header{*") {
    $line -replace ".header2_header{" , ".header2_header{background-position-y: bottom !important;"
  }

  if($line -like "*.header3_header{*") {
    $line -replace ".header3_header{" , ".header3_header{background-position-y: bottom !important;"
  }
}

$data | Set-Content .\folder\bundle.css -Force

I would like to know what is the best way to replace different lines using PowerShell.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source