set-content to WriteALL


first of all I’m neither a Powershell-Pro nor a programming expert. Anyhow I need help.

Person related Data is XXXX:

MARIS|DOC|XXXXX|GYN endgl. Brief ambulante OP|XXXXX|XXXX|8228284|1889286|XXXXXX12|XXXXX|null||null|20190719|ZWMAMB

What I Want:

Replace first ‘null’ with ‘200088’


If Text includes word ‘SAMPLEWORD’ replace ‘null’ with SAMPLEWORD’

Sampleword can differ from file to file.

Alle Files are in one folder, so the scripts needs to relate for all files in one folder.

With some help I was able to create following Powershell Code:


Get-ChildItem “C:\Users\gemuendadm\Desktop\PGTEST123*” -File -Include .txt,.dat | %{
$csv = Import-CSV $.Fullname -Delimiter “|” -Encoding Default -Header (1…15)
$csv.11 = “200088”
$csv.13 = $csv.‘4’.split(" “)[0]
($csv | convertto-csv -Delimiter “|” -NoTypeInformation | select -skip 1) -replace '”’,’’| sc -Path ($
.Fullname -replace “.txt$”,".dat")
if ($.Extension -eq “.txt”){del $.Fullname -Force}



Problem: Now there is a page break at the end of the filecontent. Is there any chance to avoid that? Or do I have to use WriteAll?

If so, can anyone help me transforming my code to WriteAll? I really have no clue.

Thank you in advance. Would be very kind.