Replace the Data Source and Initial Catalog values of WebConfig.XML
Content of XML file
<Configuration ConfiguredType=”Property” Path=”\Package.Connections[ConnStaging].Properties[ConnectionString]” ValueType=”String”>
<ConfiguredValue>Data Source=localhost;Initial Catalog=Stage;Integrated Security=SSPI; Connection Timeout = 10</ConfiguredValue>
</Configuration>
PARAM( [String]$DatabaseName='DCTarget', [String]$XML='c:\webconfig.XML', [String]$DatabaseServer='DataCenterDB01') [string]$db = 'Catalog='+ $DatabaseName [string]$dbs = 'Source='+ $DatabaseServer (Get-Content $XML) | Foreach-Object { $_ -replace "Catalog=([A-Za-z0-9_]+)", $db -replace "Source=([A-Za-z0-9_]+)", $dbs } | Set-Content $XML
The above code can be used to modify the content of any files or even copy the modified content to new file
$Sourcefile = 'c:\filename.txt'
$desfile = 'c:\Newfilename.txt'
(Get-Content $Sourcefile) | Foreach-Object {
$_ -replace 'Prashanth', 'Jayaram' `
-replace 'SQL', 'PowerShell'
} | Set-Content $destFile