We are automating our IIS server build and configuration using Powershell on Windows Server 2012 / IIS8.
The scripts create websites, application pools, set permissions, bind certificates etc. The scripts are driven from an XML file that contains details of all the websites. The scripts configure everything needed to run the websites apart from the content which is then just copied into the relevant directory.
All works fine whilst there is no content in the directory (just a default html page for testing purposes).
If we copy the applications into the directory and try to further configure the sites using Powershell, the applications that use .NET 2 and 3.5 throw the following error:
Error: There is a duplicate 'system.web.extensions/scripting/scriptResourceHandler' section defined
+ CategoryInfo : NotSpecified: (:) [Set-WebConfiguration], COMException
+ FullyQualifiedErrorId : System.Runtime.InteropServices.COMException,Microsoft.IIs.PowerShell.Provider.SetConfigurationCommand
+ PSComputerName : xxxxxxxxxxx
I have researched this topic thoroughly and it appears the problem is that the System.Web.Extensions was moved into the machine.config for .NET 4.0 applications which means that having the section defined again in the web.config is a duplicate. This makes sense except that the applications that error are .NET 2.0 or 3.5 applications running using an Application Pool set as .NET 2.0.
I believe the problem is that Powershell itself (on Windows Server 2012) runs using CLR 4.0 and therefore when making IIS configuration changes it needs to parse the configuration files hierarchically (from machine.config through to web.config). It believes the System.Web.Extensions is duplicated even though at runtime it is not (since runtime will be version 2.0). Changing the version of .NET the application pool runs as makes no difference to this problem seeing as that is about application run-time only.
There appears to be a way-around this by restricting Powershell to use CLR 2.0 only however this will not work for .NET 4.0 applications which will then report a missing section definition. So fixing the problem for one version creates a problem in the other version.
My question is, has anyone experienced this before and are there any work-around that allow Powershell to configure IIS when applications are using mixed .NET versions?
I have spent many hours on this problem and therefore would really appreciate any help.
UPDATE: Still no further with this error and I guess by the lack of comments it is not an easy one.
I was looking through the IIS 8 Powershell documentation and can see that they added a Clr property to the Set-WebConfiguration command however this has no effect because the element I am trying to modify (in this case a HTTP Redirect) ends up in the applicationhost.config file and Powershell throws a warning of:
WARNING: Ignoring -Clr value when PSPath is not 'MACHINE/WEBROOT' or 'MACHINE'.
When the modification is not to either the machine.config or the root web.config.
It appears there is simply no way around this (I consider it a bug) Perhaps renaming the web.config file in the application directory prior to any updates is the answer to Powershell will not try to parse the configuration. Any thoughts anyone has on this appreciated.