powershell - Powershell命令查找替换没有给出任何错误,但没有替换
问题描述
我正在尝试做的事情:
使用 powershell 将 .config 文件内容读取为原始字符串并找到特定字符串并替换为所需的字符串
我要查找和替换的行:
<add key="ReportServerUrl" value="http://SQL14\SQL2016_INS1/ReportServer"></add>
将上面的行替换为:
<add key="ReportServerUrl" value="http://SQL14/SQL2016_INS1/ReportServer"></add>
我试过的Powershell命令:
(Get-Content "C:\target\Server.config" -Raw).Replace("SQL14\\SQL2016_INS1/ReportServer","SQL14/SQL2016_INS1/ReportServer") | Set-Content C:\target\Server.config;
问题:
上面的语句执行没有任何错误,但上面没有按预期替换字符串
请帮忙
更新1:
尝试更换整线
(Get-Content "C:\target\Server.config" -Raw).Replace('<add key="ReportServerUrl" value="http://SQL14\SQL2016_INS1/ReportServer"></add>
','<add key="ReportServerUrl" value="http://SQL14/SQL2016_INS1/ReportServer"></add>
') | Set-Content C:\target\Server.config;
这也可以在没有错误的情况下执行,但没有完成替换。
解决方案
推荐阅读
- c# - Can someone explain what new string[,] { { L0, L1 }, { D0, D1 } }[thc, 0]; is doing?
- prolog - Implication branch doesn't see variables
- javascript - 无法使用 jquery 删除文本框
- c# - 在 ASP.Net Core 中下载文件时,我的文件从服务器正确返回,但不从 UI 保存
- here-api - HERE 地理编码不支持英国邮政编码单位吗?
- r - 如何使用 R 删除我的 googlesheets 行
- uwp - BroadFileSystemAccess is not working even it added in package.appmanfiest
- python - XGBoost 随机给出“0.5”的静态预测
- firebase - Google Analytics for Firebase 与旧的 Google Analytics for Apps 之间的应用程序唯一用户数有何区别?
- java - OAuth2-Autoconfigure:没有客户端身份验证。尝试添加适当的身份验证过滤器