Just output the extra text e.g.
(Get-Content $fileName) |
Foreach-Object {
$_ # send the current line to output
if ($_ -match "pattern")
{
#Add Lines after the selected pattern
"Text To Add"
}
} | Set-Content $fileName
You may not need the extra “n` since PowerShell will line terminate each string for you.