2012-04-26 21 views
3

web.configのsystem.serviceModelにセクションを追加するにはどうすればいいですか?それは、PowerShellでこれを行うにはあまりにも悪くはないPowerShellを使用してweb.configにセクションを追加するにはどうすればよいですか?

<system.serviceModel> 
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" /> 
<bindings> 
     <basicHttpBinding> 
     <binding name="ValidationServiceSoap" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true"> 
      <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" /> 
      <security mode="Transport"> 
      <transport clientCredentialType="Ntlm" /> 
      <message clientCredentialType="UserName" /> 
      </security> 
     </binding> 
     </basicHttpBinding> 
<bindings> 
</system.serviceModel> 
+0

なぜPowerShellからこれをやりたいのですか?それは仕事のための適切なツールではないようです。 –

+0

オートメーションデプロイメントサービスなので、手で十分です。 –

答えて

5

:後

<system.serviceModel> 
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" /> 
</system.serviceModel> 

:前

XMLは、あなたがしたいので、このアプローチはのみ動作することを

$origXml = [xml]@' 
<configuration> 
<system.serviceModel> 
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" /> 
</system.serviceModel> 
</configuration> 
'@ 

$newXml = @' 
<bindings> 
     <basicHttpBinding> 
     <binding name="ValidationServiceSoap" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true"> 
      <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" /> 
      <security mode="Transport"> 
      <transport clientCredentialType="Ntlm" /> 
      <message clientCredentialType="UserName" /> 
      </security> 
     </binding> 
     </basicHttpBinding> 
</bindings> 
'@ 

if (!$origXml.configuration.'system.serviceModel'.bindings) 
{ 
    $tempXmlDoc = new-object System.Xml.XmlDocument 
    $tempXmlDoc.LoadXml($newXml) 
    $newNode = $origXml.ImportNode($tempXmlDoc.DocumentElement, $true) 
    $origXml.configuration.'system.serviceModel'.AppendChild($newNode) 
} 

注意注射するには、単一の根要素<bindings>があります。

+0

オープンXMLファイルからこれをどのように使用できますか?上記の例では、 '$ origXml' *は以下のようになります:$ xml = [xml](Get-Content $ MainBinding)#$ MainBinding - web.configファイルからの変数 - C:\ web.config $ xml.Save($ MainBinding) –

+0

*オープンXMLファイル。 '$ newXml'は有効なXMLである文字列フラグメントです。 –

+0

Senksその仕事! –

関連する問題