# Editing web.config

**URL:** <https://forums.powershell.org/t/editing-web-config/7498>\
**Category:** PowerShell Help\
**Created:** [November 9, 2016, 9:28am UTC](https://forums.powershell.org/t/editing-web-config/7498 "2016-11-09T09:28:44Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![sharpey](https://avatars.discourse-cdn.com/v4/letter/s/838e76/32.png) [@sharpey](https://forums.powershell.org/u/sharpey)\
**Post date:** [November 9, 2016, 9:28am UTC](https://forums.powershell.org/t/editing-web-config/7498/1 "2016-11-09T09:28:44Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![rob-simmers](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/rob-simmers/32/1010_2.png) [@rob-simmers](https://forums.powershell.org/u/rob-simmers)\
**Post date:** [November 9, 2016, 1:06pm UTC](https://forums.powershell.org/t/editing-web-config/7498/2 "2016-11-09T13:06:23Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![sharpey](https://avatars.discourse-cdn.com/v4/letter/s/838e76/32.png) [@sharpey](https://forums.powershell.org/u/sharpey)\
**Post date:** [November 10, 2016, 3:42am UTC](https://forums.powershell.org/t/editing-web-config/7498/3 "2016-11-10T03:42:36Z")

</div>

> <https://gist.github.com/anonymous/be5c0077d7d18bb88a19ec4abd6f9112>

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.

---

<div class="post-metadata">

**Author:** ![rob-simmers](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/rob-simmers/32/1010_2.png) [@rob-simmers](https://forums.powershell.org/u/rob-simmers)\
**Post date:** [November 10, 2016, 10:20pm UTC](https://forums.powershell.org/t/editing-web-config/7498/4 "2016-11-10T22:20:40Z")

</div>

Take a look at this and see if you can figure it out: [https://blogs.msdn.microsoft.com/sonam\_rastogi\_blogs/2014/05/14/update-xml-file-using-powershell/](https://blogs.msdn.microsoft.com/sonam_rastogi_blogs/2014/05/14/update-xml-file-using-powershell/)

---

<div class="post-metadata">

**Author:** ![silent-steel](https://avatars.discourse-cdn.com/v4/letter/s/e5b9ba/32.png) [@silent-steel](https://forums.powershell.org/u/silent-steel)\
**Post date:** [November 11, 2016, 4:43am UTC](https://forums.powershell.org/t/editing-web-config/7498/5 "2016-11-11T04:43:04Z")

</div>

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://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/ee807834.aspx)

[https://technet.microsoft.com/en-us/library/ee790572.aspx](https://technet.microsoft.com/en-us/library/ee790572.aspx)

---

<div class="post-metadata">

**Author:** ![sharpey](https://avatars.discourse-cdn.com/v4/letter/s/838e76/32.png) [@sharpey](https://forums.powershell.org/u/sharpey)\
**Post date:** [November 11, 2016, 4:56am UTC](https://forums.powershell.org/t/editing-web-config/7498/6 "2016-11-11T04:56:21Z")

</div>

@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.

---

<div class="post-metadata">

**Author:** ![silent-steel](https://avatars.discourse-cdn.com/v4/letter/s/e5b9ba/32.png) [@silent-steel](https://forums.powershell.org/u/silent-steel)\
**Post date:** [November 11, 2016, 4:58am UTC](https://forums.powershell.org/t/editing-web-config/7498/7 "2016-11-11T04:58:58Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![rob-simmers](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/rob-simmers/32/1010_2.png) [@rob-simmers](https://forums.powershell.org/u/rob-simmers)\
**Post date:** [November 11, 2016, 8:17am UTC](https://forums.powershell.org/t/editing-web-config/7498/8 "2016-11-11T08:17:34Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:40pm UTC](https://forums.powershell.org/t/editing-web-config/7498/9 "2024-05-16T20:40:00Z")

</div>


