【问题标题】:Add a <clear /> element to WebDAV authoringRules using powershell使用 powershell 将 <clear /> 元素添加到 WebDAV authoringRules
【发布时间】:2013-05-18 01:44:30
【问题描述】:

我正在添加一个 WebDAV authoringRule 使用

Add-WebConfiguration /system.webserver/webdav/authoringRules -PSPath IIS: -Location "$site_name/$app_name/VD" -Value @{users="*";path="*";access="Read,Write"}

在某些环境中,这与父级中的相同创作规则冲突,从而引发错误。我想在 authoringRules 的开头添加一个清晰的元素,使其看起来像这样

<authoringRules>
    <clear />
    <add users="*" path="*" access="Read, Write" />
</authoringRules>

Clear-WebConfiguration 只清除现有规则。如何使用 powershell 在配置文件中添加&lt;clear /&gt; 元素?

【问题讨论】:

  • 为什么不在 web.config 文件创建后进行文本文件操作(通过 powershell 脚本)?
  • 因为与添加和删除规则的选项相比,它看起来不优雅。此外,脚本文件的其余部分主要是一系列 WebAdministration 调用。
  • 很抱歉,我只收到了这个丑陋且衣冠楚楚的建议。 :(

标签: powershell webdav


【解决方案1】:

我相信你指的是applicationHost.config。

我还发现这是 WebAdministration 命令行开关的问题,我使用 ServerManager 类解决了这个问题。我的特殊问题是 windowsAuthentication 提供程序集合,但我认为这对您不起作用。

您可能需要更正对 GetSection 的调用中的路径,但这应该可以让您非常接近您的需要。

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Web.Administration") | Out-Null

$serverManager = new-object Microsoft.Web.Administration.ServerManager
$config = $serverManager.GetApplicationHostConfiguration()
$authoringRulesSection = $config.GetSection("/system.webserver/webdav/authoringRules", "$($site_name)/$($app_name)/VD");

# Grab a reference to the collection of authoringRules
$authoringRulesCollection = $authoringRulesSection.GetCollection("authoringRules");

# Clear the current collection this also adds the <clear /> tag
$authoringRulesCollection.Clear();

# Add to the collection
$addElement = $authoringRulesCollection.CreateElement("add")
$addElement["users"] = "*";
$addElement["path"] = "*";
$addElement["access"] = "Read, Write";
$authoringRulesCollection.Add($addElement);

# Save the updates
$serverManager.CommitChanges();

【讨论】:

    猜你喜欢
    • 2017-10-22
    • 1970-01-01
    • 1970-01-01
    • 2011-03-03
    • 1970-01-01
    • 2017-03-11
    • 2018-12-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多