Objective: To find a line in server.config file and replace with some other value using powershell
String that I am trying to find in that file:
<add key="ReportServerUrl" value="http://ADEVSQL14\SQL2016_INS1/ReportServer"></add>
String to be replaced:
<add key="ReportServerUrl" value="http://ADEVSQL14/SQL2016_INS1/ReportServer"></add>
What I tried:
$filename = Get-Content "C:\target\Server.Config"
$filename -replace "<add key="ReportServerUrl" value="http://ADEVSQL14\SQL2016_INS1/ReportServer"></add>", "<add key="ReportServerUrl" value="http://ADEVSQL14/SQL2016_INS1/ReportServer"></add>"
Error which I get:
... "<add key="ReportServerUrl" value="http://ADEVSQL14\SQL2016_INS1/Rep
Unexpected token 'ReportServerUrl" value="http://ADEVSQL14\SQL2016_INS1/ReportServer"></add>"' in expression o statement.
Additional Inputs: Though I want use this functionality as part of powershell step in Azure devops pipeline, I am trying it out at command line getting similar error
Can some one suggest please.
Update1:
Tried below at command line, it executes successfully but its not getting replaced.
$filename = Get-Content "C:\target\Server.config" -Raw
$filename -replace '"http://ADEVSQL14\SQL2016_INS1/ReportServer"','"http://ADEVSQL14/SQL2016_INS1/ReportServer"'|Set-Content -Path C:\target\Server.config;