Hi I am trying to change the values of a connection string for a web.config file but getting error:
The property
'connectionString'cannot be found on this object. Verify that the property exists and can be set.
Here's the script I'm using:
$webConfig = 'C:\Users\test\Desktop\web\web.config'
$doc = (Get-Content $webConfig) -as [Xml]
$obj = $doc.configuration.appSettings.add | where {$_.Key -eq 'CommandTimeOut'}
$obj.value = '60'
$config = [xml](gc $webConfig)
$con= $config.configuration.connectionStrings.add|where-object{$_.name -eq "password"};
$con.connectionString = $con.connectionString -replace "123456", "admin1234"
$doc.Save($webConfig)
I've modified the code as below, but it's still not working and I'm getting the same error.
$cfg = [xml](gc $webConfig)
$con= $cfg.configuration.connectionStrings.add|where-object{$_.name -eq "password"};
$cfg.configuration.connectionStrings.add.connectionString=
$cfg.configuration.connectionStrings.add.connectionString -replace "123456","admin123"
$doc.Save($webConfig)
<connectionStrings>part ?