2016-06-08 84 views
1

我想换一个RTF文档的内容和比它保存为RTF文档:PowerShell的变化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文档我想我会得到同样的问题。

你的帮忙:)

回答

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 
+0

感谢工作:) –