Я пытаюсь автоматизировать обновление источника данных в файле web.config
новыми значениями с помощью PowerShell.
Вот моя строка подключения:
<connectionStrings>
<add name="abcLogging" connectionString="Data Source=(local)\abc; Trusted_Connection=True; Persist Security Info=True; Enlist=true; Initial Catalog=abcLogDB" providerName="System.Data.SqlClient" />
</connectionStrings>
Сценарий PowerShell:
$newstring = '"Data Source=(test)\abc; Trusted_Connection=True; Persist Security Info=True; Enlist=true; Initial Catalog=abcLogDB" '
$oldstring = '"Data Source=(local)\abc; Trusted_Connection=True; Persist Security Info=True; Enlist=true; Initial Catalog=abcLogDB" '
$XmlDocument = [xml](Get-Content "D:\abc\Web.config");
$value = $XmlDocument.configuration.connectionStrings.add.connectionstring
$value = $value -replace "$oldstring","$newstring" | Set-Content -PassThru
Я получил следующую ошибку при запуске вышеуказанного скрипта.
The regular expression pattern "Data Source=(local)\abc; Trusted_Connection=True;
Persist Security Info=True; Enlist=true; Initial Catalog=abcLogDB" is not valid.
At line:5 char:1
+ $value = $value -replace "$oldstring","$newstring" | Set-Content -Pas ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: ("Data Source=(l...og=OnityLogDB" :String) [], RuntimeException
+ FullyQualifiedErrorId : InvalidRegularExpression