尝试使用Powershell Set-WebConfigurationProperty时无法识别的元素“ProviderOption”

我正在尝试构build一个Powershell脚本来自动化我们部署的Web应用程序的连接string更改。

我正在尝试使用WebAdministration命令Set-WebApplicationProperty但收到有关Unrecognized element: 'providerOption'的错误Unrecognized element: 'providerOption'

 PS IIS:\Sites\Default Web Site\VirtualPath> Set-WebConfigurationProperty "//connectionStrings/*[@name='DefaultConnection']" -Name ConnectionString -Value "<NEW CONNECTION STRING>" -PSPath (Get-Location).Path Set-WebConfigurationProperty : Filename: \\?\C:\Windows\Microsoft.NET\Framework64\v4.0.30319\CONFIG\web.config Line number: 53 Error: Unrecognized element 'providerOption' At line:1 char:1 + Set-WebConfigurationProperty "//connectionStrings/*[@name='DefaultConnection']" ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Set-WebConfigurationProperty], COMException + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException,Microsoft.IIs.PowerShell.Provider.SetConfigurationPropertyCommand 

我发现有关StackOverflow上的同一错误的一些信息,但它似乎与.NET 4.0的原始版本有关: https : //stackoverflow.com/questions/21308965/unrecognized-element-provideroption

一些额外的环境信息:

操作系统: Windows Server 2008 R2
IIS: 7.5
Powershell: v4.0
.NET Framework版本: 4.5.2

另外值得注意的是,这个命令在Window 8.1,IIS 8.5,Powershell 4.0,.NET 4.5.2上工作得很好

编辑:在一个预感我比较Web.config指定的错误之间的工作机器和没有的机器之间的错误。 他们是相同的。

事实certificate,使用Powershell是一个红鲱鱼。 IIS使用位于C:\Windows\System32\inetsrv\config\schema中的文件来validationWeb服务器使用的各种xmlconfiguration文件。 在IIS 7和IIS 7.5上, FX_schema.xml缺lessproviderOption的声明。

我的解决方法是通过将以下内容添加到名为"FX_schema.patch.xml"此目录中的另一个文件来修补架构文件:

 <!-- IIS 7.0 and IIS 7.5 contain incorrect system.codedom sections in their FX_schema.xml files. This version was taken from IIS 8.5 and contains the correct validations for the default web.config in the CLR 4.0 folder. This file is only required on Windows Vista, 7, Server 2008 and Server 2008 R2. --> <configSchema> <sectionSchema name="system.codedom"> <element name="compilers"> <collection addElement="compiler" removeElement="remove" clearElement="clear"> <attribute name="language" type="string" isCombinedKey="true" /> <attribute name="extension" type="string" isCombinedKey="true" /> <attribute name="type" type="string" /> <attribute name="warningLevel" type="int" /> <attribute name="compilerOptions" type="string" /> <collection addElement="providerOption" > <attribute name="name" type="string" isCombinedKey="true" /> <attribute name="value" type="string" isCombinedKey="true" /> </collection> </collection> </element> </sectionSchema> </configSchema> 

该文件与现有的FX_schema.xml合并,并允许我的Webpipe理命令成功完成。