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

标签 html powershell outlook rtf

我想更改 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/

相关文章:

html - 如何在 Bootstrap 中命名 div 类以在外部 CSS 中编辑它们

html - 在我的浏览器中查找网页的当前宽度

powershell - Powershell:与x86 powershell/ise一起运行的脚本

python - Powershell Windows Server 2012 .Path错误安装Hortonworks Data Platform(HDP)

vb.net - 如何使用 VSTO 2005 导入或创建 Outlook 2003 规则 (.rwz)?

vba - 如何在 MS Office 2003 中使用 VBA 将成员添加到 Exchange 通讯组列表

html - 如何删除链接 <a> 和它位于 <li> 中的列表项之间的所有填充?或者...点击 <li> 打开里面的链接?

javascript - 我如何在 jquery 的帮助下在 codeigniter 中匹配两个电子邮件地址

c# - 在WPF应用程序中使用powershell通过uninstallString卸载应用程序

c# - 使用 C# 编辑 Outlook 联系人