Add the <clear / "> element to AuthoringRules WebDAV using powershell
I am adding AuthoringRule for WebDAV using
Add-WebConfiguration /system.webserver/webdav/authoringRules -PSPath IIS: -Location "$site_name/$app_name/VD" -Value @{users="*";path="*";access="Read,Write"} In some environments, this contradicts the same authorship rule in the parent object and thus generates an error. I want to add a clean element to the top of authoringRules so that it looks something like this.
<authoringRules> <clear /> <add users="*" path="*" access="Read, Write" /> </authoringRules> But Clear-WebConfiguration only clears existing rules. How to use powershell to add a <clear /> element to a configuration file?
I believe you are referring to applicationHost.config.
I also found that this is a problem with WebAdministration commands, I solved it using the ServerManager class. My particular problem was the Windows Authentication Provider Collection, but I see no reason why this will not work for you.
You may need to fix the path in the GetSection call, but this should come 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();