I have a problem with the coding and the processing/handling with my script.
The coding of my PS1 sript is UTF8. I load a text file (also UTF8) into my powershell script and read some content like
$inserttext= “C:\user\insert\mytext.txt”
$insert = Get-Content -path $inserttext | where {$_ -match “Home-Nr.:”}
$insert = ($insert).replace(“Home-Nr” , “”)
($insert = “MainStreet Home-Nr.: 83”)
There is the problem with the coding, because the replace option does not work. Nothing happend - got the same output like before or the “get-content” function does not work. I think in the backgroud the “Home-Nr.:” has some different/special letters.
Are you trying to actually update the file? In it’s current form, it will only edit that line in memory. The previous answer should help you get the modified line in the variable. Here are two examples of how you can modify the line and update the file. For the sake of other readers I have provided a test text file.
thanks, I have corrected it - but in my script all is fine - just a failure by threat creation.
you use a differt syntax like - I have to check this: $replace = $insert -replace “Home-Nr” ; $replace
@Doug: when the script has finished, the content of the variable will be stored in another txt-file - which works fine.
Is just the fact, that the content of the line is not replaced correct. I will also check your code