Author Posts

November 9, 2016 at 2:58 pm

Hi,

I'm new here, so apologies if this is an obvious answer. I have tried to find a cmdlet that would achieve this edit, but I'm not having much luck. I would like to add the requestFiltering section at SITE level [ie: web.config].

Only examples I've found online would only achieve this at server-level via an appcmd command. So I've resorted to trying to write a script to edit the web.config directly, to inject the section into the section.

Is there anything obvious I can use, or can someone please suggest some quick code please?

Thanks in advance,
Carl.

November 9, 2016 at 6:36 pm

A web config file is just a XML file. There are many articles on opening an XML file and adding a node, editing a property or element utilizing Powershell. Without seeing an example, it's going to be difficult to help you. This site will eat html\XML, so you will need to use github if you do want to post an example of your XML and desired result.

November 10, 2016 at 9:12 am

Hi Rob,

Appreciate the reply. I have a web.config that already has the system.web tags, but want to insert the rest of the structure inside those tags.

Carl.

November 11, 2016 at 10:13 am

Hi,

I'll advise against using any xml commands to change web.config. If you have a different xml file, then by all means.

For web.config files, best to use Get-WebConfiguration and Get-WebConfigurationProperty and the equivalent Set commands.

https://www.iis.net/learn/manage/powershell/powershell-snap-in-changing-simple-settings-in-configuration-sections

https://technet.microsoft.com/en-us/library/ee807834.aspx

https://technet.microsoft.com/en-us/library/ee790572.aspx

November 11, 2016 at 10:26 am

@Rob: Thanks for the links, I shall check those out – looks promising.

@Arie: I started off looking at these, but from what I can gather, they only allow you to set these settings at server-level in IIS and not at site-level as required in this instance.

November 11, 2016 at 10:28 am

AFAIK, all you need to do is supply the path.

The commands will work to what ever depth you give the parameters you supply, as long as it exists.

November 11, 2016 at 1:47 pm

Reading through the documentation notes it appears that those commands check against a schema which would prevent you from setting incorrect web.config items. Thanks for the reference, another feather in the cap.