Im trying to create a ps script which appends the string ;history directly after ;stylesheets but currently the script is creating an additional line when i want it to append it directly after.
This is how it is suppose to look
;stylesheets;history
But this is what happens
;stylesheets
;history
Can someone explain why?
(Get-Content K:\Temp\test.properties) |
Foreach-Object {
$_
if ($_ -match ";stylesheets")
{ ";history"
}
} | Set-Content K:\Temp\test.properties
Alternative solution:
(Get-Content K:\Temp\test.properties).Replace(';stylesheets',';stylesheets;history') |
Set-Content K:\Temp\test.properties
You are getting two lines because you are returning two objects when you match. @($_,";history") and each object is written as a line. You could combine them into one string when you match.
(Get-Content K:\Temp\test.properties) |
Foreach-Object {
if ($_ -match ";stylesheets") {
"$_;history"
} else {
$_
}
} | Set-Content K:\Temp\test.properties
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With