1

I want to replace the connectionString in the web.config of a hosted iis service at a remote computer with msdeploy and powershell.

The script runs without errors:

 $iisPath = "$iisServicePath,computerName=$computerName,userName=$userName,password=$password"

 & "C:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe" `
"-source=contentPath=$iisPath" `
'-verb=sync' `
'-verbose' `
'-allowUntrusted' `
"-dest=contentPath=$iisPath" ` 
'-setParam=kind=TextFile,match="configuration/connectionStrings/add[@name=MyEntities]/@connectionString",scope=web\.config$,value="$newConString"';

The verbose output of the script says:

Verbose: The synchronization completed in 1 pass(es).
Total changes: 0 (0 added, 0 deleted, 0 updated, 0 parameters changed, 0 bytes copied)

The connectionString Attribute`s value was not replaced.

How can I do that?

UPDATE

That is the error message I get now:

Verbose: Parameter entry 'MSDeploySetParameter-2080747909/1' could not be applied to 'MyWebSite/MyService\Web.config'. Deployment will continue with the original data. Details:
No matches were found for the search string '`"configuration/connectionStrings/add[@name=MyEntities]/@connectionString`' (type 'TextFile').
Verbose: Attribute 'size' equality changed to False when comparing filePath (MyWebSite/MyService\Web.config) to MyWebSite/MyService\Web.config because of rule Parameterizat
ion.
Verbose: Source filePath (MyWebSite/MyService\Web.config) does not match destination (MyWebSite/MyService\Web.config) differing in attributes (parameters). Update pending.
Verbose: Source filePath (MyWebSite/MyService\Web.config) replaced with changed attributes (size['3710','3707']) because of rule Parameterization.
Info: Updating file (MyWebSite/MyService\Web.config).
Verbose: The dependency check 'DependencyCheckInUse' found no issues.
Verbose: The synchronization completed in 2 pass(es).
Total changes: 1 (0 added, 0 deleted, 1 updated, 0 parameters changed, 3707 bytes copied)

With this changed code:

 & "C:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe" `
"-source=contentPath=$iisPath" `
'-verb=sync' `
'-verbose' `
'-allowUntrusted' `
"-dest=contentPath=$iisPath" `
'-setParam=kind=TextFile,match=`"configuration/connectionStrings/add[@name=MyEntities]/@connectionString`",scope=web\.config$,value=`"$newConString`"';

1 Answer 1

0

Change the last line here, you're using single quotes, which will be interpretted exactly as typed (so it wouldn't swap in the value for a variable, for instance)

I've replaced your single quotes with double, and gone ahead and escaped the inner quotes as well. If this doesn't work, let me know!

-setParam=kind=TextFile,match=`"configuration/connectionStrings/add[@name=MyEntities]/@connectionString`",scope=web\.config$,value=`"$newConString`" ";
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.