Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
添加一个<;清除/>;元素到使用powershell的WebDAV创作规则_Powershell_Webdav - Fatal编程技术网

添加一个<;清除/>;元素到使用powershell的WebDAV创作规则

添加一个<;清除/>;元素到使用powershell的WebDAV创作规则,powershell,webdav,Powershell,Webdav,我正在使用添加WebDAV创作规则 Add-WebConfiguration /system.webserver/webdav/authoringRules -PSPath IIS: -Location "$site_name/$app_name/VD" -Value @{users="*";path="*";access="Read,Write"} 在某些环境中,这与父级中的同一创作规则冲突,因此引发错误。我想在authoringRules的开头添加一个clear元素,使其看起来像这样 &l

我正在使用添加WebDAV创作规则

Add-WebConfiguration /system.webserver/webdav/authoringRules -PSPath IIS: -Location "$site_name/$app_name/VD" -Value @{users="*";path="*";access="Read,Write"}
在某些环境中,这与父级中的同一创作规则冲突,因此引发错误。我想在authoringRules的开头添加一个clear元素,使其看起来像这样

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


但是
清除网络配置
仅清除现有规则。如何使用powershell将
元素添加到配置文件?

我相信您指的是applicationHost.config

我还发现这是WebAdministration命令的一个问题,我使用类解决了这个问题。我的特别问题是windowsAuthentication providers集合,但我看不出这对您不起作用的原因

您可能需要更正调用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();
[System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.Web.Administration”)| Out Null
$serverManager=新对象Microsoft.Web.Administration.serverManager
$config=$serverManager.GetApplicationHostConfiguration()
$authoringRulesSection=$config.GetSection(“/system.webserver/webdav/authoringRules”,”$($site\u name)/$($app\u name)/VD”);
#获取对authoringRules集合的引用
$authoringRulesCollection=$authoringRulesSection.GetCollection(“authoringRules”);
#清除当前集合这也会添加标记
$authoringRulesCollection.Clear();
#添加到集合中
$addElement=$authoringRulesCollection.CreateElement(“添加”)
$addElement[“用户”]=“*”;
$addElement[“路径”]=“*”;
$addElement[“访问”]=“读、写”;
$authoringRulesCollection.Add($addElement);
#保存更新
$serverManager.CommitChanges();

为什么不在创建web.config文件后进行文本文件操作(通过powershell脚本)?因为与添加和删除规则的选项相比,它似乎不雅观。另外,脚本文件的其余部分主要是一系列的Web管理调用。很抱歉,我只得到了一个丑陋的、穿着糟糕的建议:(