Q:

Editing a file using search string in powershell

I am having difficulties in writing a powershell/batch script which needs to search a string in the input file, copy the content of line to next line and replace the string by another string.
For example if my file has following content
James is awesome.

Ryan is handsome.

Henry is a bad boy.

Jim is studious

And output should look like when script is called with inputs "***Henry***" & "***Glenn***"
James is awesome.

Ryan is handsome.

***Henry*** is a bad boy.

***Glenn*** is a bad boy.

Jim is studious

A:

This is the function that will find word in a line, if found duplicate the line with new word.
Function ReplaceAndDuplicate([string[]]$drseus, $thing1, $thing2) {
  $drseus | % { 
    $_
    if ($_ -match $thing1) {
      $_ -replace $thing1, $thing2
    }
  }
}

Usage:
ReplaceAndDuplicate (Get-Content C:\temp\file.txt) "Henry" "Glenn"

And output looks like
James is awesome.
Ryan is handsome.
Henry is a bad boy.
Glenn is a bad boy.
Jim is studious

