Find and backup web.config file

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)

Robby,
Welcome to the forum. :wave:t4:

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 <---- Click :point_up_2:t4: :wink: