Powershell – IIS Set Connection String in web.config [Solution]

IIS Set Connection String in web.config using the Web-Administration powershell module

So in the web.config file  for “MyApplication” application under “Default Web Site”, I have a connection string called “MyChartsConnection”, that I want to change the connection string as I am modifying it for Production use , changing server name and username password, plus some parameters  that i do not need in test.

So if we break down that middle line which is soooooo long what we see is that there are actually 3 parameters:

connectionString
name
providerName

NOTE:
It is confusing that you have connectionString and connectionStrings, so bear with me on that.
additionally bear in mind a lot of the IIS cmdlets can be case sensitive with properties , so always copy and paste what you see returned otherwise you will get frustrated as you type in ProviderName instead of providerName and get undesired results

So knowing that I can use the get-webConfiguration cmdlet, filtering on the connectionStrings section and the name “MyChartsConnection” 

So if we look at what is returned we see the 3 parameters returned as properties

So we can change those 3 things using Set-WebConfigurationProperty.

In this example I am changing the connection string using

-name  parameter and saying i want to change the property ‘connectionString’

As  you can see I have to change the full string in one go, I cannot change just part of it.

 

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.