IIS Config Backup With Robocopy

Recently I have been brainstorming about having an automated way of backing up IIS configs to a shared folder. Just imagine having your web servers going down and having to re-add all the website settings and bindings for hundreds of websites. I know for a fact that I would need a few strong drinks.

Let’s just have a cocktail and make a PowerShell script to do it for you instead.

I will post the script below. But for now, let’s break it down.

First we need to set the day of the week if you are going to be making daily backups.

Now we need to set the variables for the folders.

Let’s set the variables for email.

Now we need to define the actual backup of the IIS Configs.

Move it over to your share.

IIS doesn’t allow multiple names or even overwriting the configs. Understandable since you may need a weeks worth of backups. But we need to delete the old logs.

Now is the real helpful part. Since you don’t want to check the servers everyday to see if the backups were successful, you will need an email.

That’s the script. It’s pretty simple and straight to the point. Any system running Windows 10 or later or any Windows Server OS will allow this script to be run.

It’s best to run this script with task scheduler. Task scheduler will even keep a nice history list if it fails or not.

Below is all the code combined and allows you to save and run.