添加一个 <clear/>使用 powershell 将元素添加到 WebDAV authoringRules [英] Add a <clear /> element to WebDAV authoringRules using powershell
问题描述
我正在添加一个 WebDAV authoringRule 使用
I am adding a WebDAV authoringRule using
Add-WebConfiguration /system.webserver/webdav/authoringRules -PSPath IIS: -Location "$site_name/$app_name/VD" -Value @{users="*";path="*";access="Read,Write"}
在某些环境中,这与父级中的相同创作规则相冲突,从而引发错误.我想在 authoringRules 的开头添加一个 clear 元素,使其看起来像这样
In some environments, this is conflicting with the same authoring rule in the parent, and thus throwing an error. I want to add a clear element to the start of the authoringRules so it looks something like this
<authoringRules>
<clear />
<add users="*" path="*" access="Read, Write" />
</authoringRules>
但是 Clear-WebConfiguration
只清除现有规则.如何使用 powershell 将
元素添加到配置文件中?
But Clear-WebConfiguration
only clears the existing rules. How do I use powershell to add a <clear />
element to the config file?
推荐答案
我相信您指的是 applicationHost.config.
I believe you are referring to applicationHost.config.
我也发现了 WebAdministration commandlet 的一个问题,我使用 ServerManager 类.我的特殊问题是 windowsAuthentication 提供程序集合,但我看不出为什么这对您不起作用.
I also found this an issue with the WebAdministration commandlets, I solved it using the the ServerManager class. My particular issue was with the windowsAuthentication providers collection, but I see no reason why this wouldn't work for you.
您可能需要更正对 GetSection 的调用中的路径,但这应该会让您非常接近您所需要的.
You may have to correct the path in the call to GetSection but this should get you very close to what you need.
[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();
这篇关于添加一个 <clear/>使用 powershell 将元素添加到 WebDAV authoringRules的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!