# Find and backup web.config file

**URL:** <https://forums.powershell.org/t/find-and-backup-web-config-file/20931>\
**Category:** PowerShell Help\
**Created:** [November 15, 2022, 10:13pm UTC](https://forums.powershell.org/t/find-and-backup-web-config-file/20931 "2022-11-15T22:13:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![robby.atkins](https://avatars.discourse-cdn.com/v4/letter/r/e68b1a/32.png) [@robby.atkins](https://forums.powershell.org/u/robby.atkins)\
**Post date:** [November 15, 2022, 10:13pm UTC](https://forums.powershell.org/t/find-and-backup-web-config-file/20931/1 "2022-11-15T22:13:37Z")

</div>

Would like to find a way to automatically backup the web.config file of a website without having to go into the script and change the path. Backup-WebConfiguration backs up the website files but not the web.config. We are setting a script that adds changes for CPS text and would like to bakup the file before the text is applied. Here is a example:

# $site = “”

```
$currentDate = (get-date).tostring("mm_dd_yyyy-hh_mm") # month_day_year - hours_mins
$backup = $Website + "_$currentDate"    
# Get the content of the config file and cast it to XML and save a backup copy labeled .bak followed by the date
$xml = [xml](get-ChildItem $Website)    
#save a backup copy
$xml.Save($backup)

```

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [November 27, 2022, 9:23pm UTC](https://forums.powershell.org/t/find-and-backup-web-config-file/20931/2 "2022-11-27T21:23:48Z")

</div>

Robby,  
Welcome to the forum. 👋🏽

Where and how do you define the variable `$Website`?

And since the config file already is an XML file why don’t you simply copy it with `Copy-Item`?

Regardless of that - the code you posted got a little messed up by the forum software.

When you post code, sample data, console output or error messages please format it as code using the _preformatted text_ button ( **\</\>** ). Simply place your cursor on an empty line, click the button and paste your code.

Thanks in advance

[How to format code in PowerShell.org](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/2X/b/bee50c628238f2c076c0504efb6b15f2fb11f002.gif) \<---- Click 👆🏽 😉

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/1X/385e4f9fe133561ad30a814262fe0e0ae6bc3ef0.png) [@system](https://forums.powershell.org/u/system)\
**Post date:** [February 10, 2024, 5:34pm UTC](https://forums.powershell.org/t/find-and-backup-web-config-file/20931/3 "2024-02-10T17:34:07Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
