Powershell更改RTF文档并另存为RTF文档

时间:2016-06-08 12:06:42

标签: html powershell outlook rtf

我想更改RTF文档的内容,而不是将其保存为RTF文档:

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

当我这样做的时候,在我改变内容之后,我无法用文字打开它(我可以,但有一些奇怪的字符)。

当我这样尝试时:

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

保存后没有任何改变,但在电源外壳中它被更改,图像后面的超链接现在不会隐藏在图像后面。

当我制作2替换时,其中一个不可见。

更改rtf后,我必须更改htm文档,我想我会遇到同样的问题。

求救:)

1 个答案:

答案 0 :(得分:2)

使用Get-Content cmdlet加载文件,进行替换,最后使用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