Hi, I'm trying to change the connection string values for the web.config file, but get an error:
The 'connectionString' property could not be found on this object. Verify that the property exists and can be set.
Here's the script I use:
$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 changed the code as below, but it still does not work, and I get 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)
source share