我试图用脚本替换文本文件中的文本。我想替换
SSLCertificateFile "D:/folder/location/file.cer"
与
SSLCertificateFile "D:/folder/location/NewFile.cer"
我写道:
(Get-Content C:\foler\location\httpd-ssl.conf) -replace ('[SSLCertificateFile "D:/folder/location/file.cer"]', 'SSLCertificateFile "D:/folder/location/NewFile.cer"') | Set-Content C:\foler\location\httpd-ssl.conf
这是用SSLCertificateFile替换整个httpd-ssl.conf" D:/folder/location/NewFile.cer"
帮助
答案 0 :(得分:0)
-replace使用正则表达式,你必须在正则表达式中转义具有特殊含义的字符 ?模式中的方括号是什么?
$Search = [RegEx]::escape('SSLCertificateFile "D:/folder/location/file.cer"')
$Replace= 'SSLCertificateFile "D:/folder/location/NewFile.cer"'
$File = 'C:\foler\location\httpd-ssl.conf'
(Get-Content $File) -replace $Search,$Replace|
Set-Content $File