I'm trying to change app settings in web.config file using PowerShell
Following is web.config file;
<configuration>
<connectionStrings>
<add name="TestDBEntities" connectionString="metadata=res://*/TestProject.csdl|res://*/TestProject.ssdl|res://*/TestProject.msl;provider=System.Data.SqlClient;provider connection string="data source=SQL01;initial catalog=TestDB;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
<appSettings>
<add key="ActivePeriod" value="false" />
<add key="Environment" value="UAT" />
<add key="authmode" value="4" />
<add key="IsEncryptedConfig" value="true" />
<add key="LogErrorsToText" value="true" />
</appSettings>
</configuration>
I'm want to the change the app settings values. For that I have stored all the corresponding values in PowerShell dictionary. Here is my dictionary looks like;
Key Value
----- -----
ActivePeriod true
Environment prod
LogErrorsToText false
Now, I want to match each of the Dictionary key's with the appsetting key's. if any of the dictionary key matches with appsetting key, it should replace the corresponding values. In my case, I'm expecting following output;
<configuration>
<connectionStrings>
<add name="TestDBEntities" connectionString="metadata=res://*/TestProject.csdl|res://*/TestProject.ssdl|res://*/TestProject.msl;provider=System.Data.SqlClient;provider connection string="data source=SQL01;initial catalog=TestDB;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
<appSettings>
<add key="ActivePeriod" value="true" />
<add key="Environment" value="prod" />
<add key="authmode" value="4" />
<add key="IsEncryptedConfig" value="true" />
<add key="LogErrorsToText" value="false" />
</appSettings>
</configuration>
Can someone please suggest me possible solutions. Thanks in advance.