以下代码有效,但它替换了它找到的所有文本。有没有办法只替换第一次出现。我已经尝试了 4 天。
请帮忙。
cls
$fileName = "c:\test\bmsbackuplog.htm"
$findstring=Select-string $fileName -Pattern "The backup of volume system reserved" -list
$replacement = "<tr><td>Change using this line</td></tr>"
$firstdata=$findstring[0].Line
$both="$firstdata$replacement"
$match ="The backup of volume system reserved*.*"
(Get-Content ($fileName)) -replace $match,$both | Set-Content "c:\test\bmsbackuplog.htm"