Rewrite the first line in a text file
<p>I'm trying to rewrite the first line in a text-file in a function in PowerShell.
This is my code but it doesn't work.</p>

<pre><code>$deel = Get-Content E:\Examen\Nieuw\deel.txt

function lijnHerschrijven($naam1, $naam2) {
    ($deel) | ForEach-Object {$_ -replace "$naam1", "$naam2"} |
        Set-Content E:\Examen\Nieuw\deel.txt
}
lijnHerschrijven("Deel 1", "Deel 2")
</code></pre>

<p>So the file has 1 line in it &rarr; "Deel 1", and when I call the function it has to replace "Deel 1" into "Deel 2". But the file keeps saying "Deel 1".</p>