Powershell 更改 RTF 文档并另存为 RTF 文档
Powershell change RTF Document and save as RTF Document
我想更改 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 替换其中的一个时,它不是更明显。
更改 rtf
后,我必须更改 htm
文件,我想我会遇到同样的问题。
求助:)
使用 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
我想更改 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 替换其中的一个时,它不是更明显。
更改 rtf
后,我必须更改 htm
文件,我想我会遇到同样的问题。
求助:)
使用 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