【问题标题】:add <clear /> and <remove name=something /> tag to collections in applicationHost.config or web.config using Powershell webadministration module使用 Powershell webadministration 模块将 <clear /> 和 <remove name=something /> 标签添加到 applicationHost.config 或 web.config 中的集合
【发布时间】:2013-08-31 00:37:55
【问题描述】:

根据标题,有人可以帮忙吗?

只是一个例子:

<system.ftpServer>
    <security>
        <ipSecurity>
            <add ipAddress="1.2.3.4" subnetMask="255.255.255.0" />
        </ipSecurity>
    </security>
</system.ftpServer>

我想添加一个标签作为第一个元素,以停止从其父元素委派的元素。 以及之后。

所以它看起来像这样:

<system.ftpServer>
    <security>
        <ipSecurity>
            <clear />
            <remove ipAddress="1.1.1.1" />
            <add ipAddress="1.2.3.4" subnetMask="255.255.255.0" />
        </ipSecurity>
    </security>
</system.ftpServer>

【问题讨论】:

    标签: shell powershell iis-7 scripting


    【解决方案1】:

    在不诉诸 xml 操作的情况下,以下答案可能会帮助您开始解决此问题:

    Add a 'clear' element to WebDAV authoringRules using powershell

    【讨论】:

      【解决方案2】:

      这种方法可能不被推荐,但如果你想使用 xml 来做,那么你可以这样做。

      $filepath = "C:\scripts\so\webdavconfig.xml"
      $xml = [xml](get-Content -Path $filepath)
      $elem = $xml.CreateElement("clear");
      $elem2 = $xml.CreateElement("remove");
      $attr = $xml.CreateAttribute("ipAddress");
      $attr.Value="1.1.1.1";
      $elem2.Attributes.Append($attr);
      $xmlnode = $xml."system.ftpserver".security.ipSecurity
      $xmlnode.AppendChild($elem);
      $xmlnode.AppendChild($elem2);
      $xml.Save($filepath);
      $xml."system.ftpserver".security.ipSecurity
      

      【讨论】:

        猜你喜欢
        • 2011-01-13
        • 1970-01-01
        • 1970-01-01
        • 2012-05-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-07-30
        相关资源
        最近更新 更多