Felix Wohlgemuth Felix Wohlgemuth - 7 months ago 23
HTML Question

Powershell change RTF Document and save as RTF Document

I want to change the content of a RTF document and than save it as RTF document

$defaultRtfFile>> "C:\Users\user\Desktop\Outlokk-Signature\Test.rtf"

When i do it like this ,after i changed the content, i cant open it in word (i can but there are some strange characters)

When i try it like this

$Rtb = New-Object -TypeName System.Windows.Forms.RichTextBox
$Rtb.Rtf = [System.IO.File]::ReadAllText("C:\Users\fwohlgemuth\Desktop\Outlokk-Signature\DefaultFiles\default.rtf")

after saving it nothing is changed but in power shell it is changed and the hyperlinks behind images are now not hidden behind the image.
When i make 2 Replace one of them isn't more visible

After changing the rtf i have to change a htm document i think i will get there the same problem

thy for help :)


Use the Get-Content cmdlet to load the file, do your replacements and finally write it back using the Set-Content cmdlet.


$filepath = 'Your_file_Path'
$content = Get-Content $filepath -raw
$content = $content -replace 'ReplaceMe', 'IReplacedYou'
$content = $content -replace 'ReplaceMe2', 'IReplacedYou2'
$content | Set-Content $filepath