Powershell Replace specific string in files and save

Viewed 15

Hello PowerShell cracks, I need some help in a script. I want to replace a specific string in a file, a version info, with a variable. From searching google, following script should do it, by using the -replace.

$filecontent = Get-Content -Path $temp
$newContent = $filecontent -replace 'V#+#+#', $version
$newContent | Set-Content -Path $temp

The file is a .kl (KAREL)-file and looks like that:

---+----------------------------------------------------------------------------------------------+
-- | Mainfile                                                         |
---+----------------------------------------------------------------------------------------------+
PROGRAM plx
%COMMENT = 'PLx Com V#+#+#'
%NOLOCKGROUP
%NOPAUSESHFT
%NOPAUSE = ERROR + COMMAND + TPENABLE
%NOABORT = ERROR + COMMAND
%stacksize = 8000
%environment strng
%environment uif
%environment sysdef
%environment memo
%environment kclop
%environment bynam
%environment fdev
%environment flbt
%environment regope
%include klevccdf
%include klevkeys
%include klevkmsk

It should replace the "V#+#+#" string in line 5 with a string from a variable. But PowerShell do not find the string in the file content. I don't understand where's the issue.

Thanks in advance for your help.

0 Answers
Related