我想更改 RTF 文档的内容,而不是将其另存为 RTF 文档:
$defaultRtfFile>> "C:\Users\user\Desktop\Outlokk-Signature\Test.rtf"
我这样做的时候,我改完内容后,用word打不开(可以,但是有一些奇怪的字符)。
当我这样尝试时:
$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)
保存后没有任何变化,但在 power shell 中发生了变化,图像后面的超链接现在不会隐藏在图像后面。
当我制作 2 Replace 其中一个时,不会更明显。
更改 rtf
后,我必须更改 htm
文档,我想我会遇到同样的问题。
你的帮助:)
最佳答案
使用 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
关于html - Powershell 更改 RTF 文档并另存为 RTF 文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37702031/