Search code examples
powershellrandomtextpowershell-2.0powershell-3.0

Replacing the contents or following text of a keyword in Powershell


I want to replace the contents of a certain keyword or text in a .txt file Example:

word.pass=haiwueuofbdkoabqo1738379

I want to replace the contents or text of word.pass=

I only know about replacing a certain keyword but not the following text or the line


Solution

  • In it's simplest form you can look for a line that starts with word.pass= and replace the whole line:

    $a = "word.pass=haiwueuofbdkoabqo1738379"
    if ($a -like "word.pass=*") {
        $a = "word.pass=SomeNewText"
    }
    write-host $a
    

    This answers the question you've posted, but I suspect that there's more to this.