I'm currently writing a PowerShell script to help out a user.
I am reading a file which is generated by a program into an array.
I iterate through it with a foreach and make changes to it as necessary.
Then I want to write the text, including changes, into a new file.
Param(
[Parameter(Mandatory=$true, Position=0, HelpMessage="pulse?")]
[string]$pulse,
[Parameter(Mandatory=$true, Position=1, HelpMessage="milimeter?")]
[string]$milimeter
)
$textfile = Get-Content C:\11111_O.jbi
foreach($string in $textfile) {
$string -match '(EC\d*=)'
if($matches) {
[string]$regex = $matches[1]
[string]$replacement = ($regex + $pulse + ',')
$string = $string -replace '(EC\d*=)', "$replacement"
}
}
$textfile | Out-File -FilePath C:\new_file.jbi
But even though i have checked the code inside the foreach multiple times (it does what it's supposed to do to $string). The output of $textfile always stays the same.
How can I get $textfile to update and reflect the changes I want to do to it in my foreach?