Modify webconfig connectionstring using powershell


 [CmdletBinding()]
  param ($PT_connectionstring_new =  "newpassword")  
  $webConfig = 'D:\Web.config'

Function updateWebConfig($config) 
{ 
$doc = (Get-Content $config) -as [Xml]
$root = $doc.get_DocumentElement();
$activeConnection = $root.connectionStrings.SelectNodes("add")|?{$_.name -eq "PROD"};
$activeConnection.SetAttribute("connectionString",$PT_connectionstring_new);
$doc.Save($config)
} 

updateWebConfig($webConfig)